Do you use the 'My' namespace in VB.NET? [

2020-04-02 06:58发布

VB.NET has the "my" namespace, but how many VB.NET developers actually use it?

  • if you don't, why?
  • if you are using it, why?

I'm considering building a framework for VB.NET, and using the My namespace to plug it into VB seems like a reasonable idea. Is it?

标签: vb.net
12条回答
萌系小妹纸
2楼-- · 2020-04-02 07:12

Love the My! Anything that helps me get the job done faster, and provides code for solutions that I don't have to write, the better!

查看更多
祖国的老花朵
3楼-- · 2020-04-02 07:15

I really like the "My" Namespace in VB.NET and I always use it in my WindowsForms applications, because it is very intuitive.

I use primarily these categories:

  • My.Computer: primarily for file system and network purposes
  • My.Application: Version number, current directory
  • My.Resources: Access to resources used by the application residing in resource files in a strongly typed manner.
  • My.Settings: very handy

I think, if your extensions for My of your framework fit well, then many VB.NET programmers would appreciate them.

查看更多
兄弟一词,经得起流年.
4楼-- · 2020-04-02 07:18

I never use the My namespace (I'm a C# developer), but my VB co-worker doesn't as well. I found the My members not necessary, because in many cases, they're counter-intuitive for me, e.g. in my opinion opening a file has something to do with IO (hence System.IO.File) and not with my computer (My.Computer.FileSystem). They always seem so scattered and bunched together.

It's just some re-roll of functionality that is already available otherwise, from all languages. And I don't like depending on Microsoft.VisualBasic.dll when I'm developing for .NET - I always prefer System.*.

And then, it's always kind of limited. I see VB developers struggle with their app when they can't find something in the My namespace, because they can't imagine that you can use something in the System namespace. That of course is not a problem of the My namespace itself.

查看更多
不美不萌又怎样
5楼-- · 2020-04-02 07:20

I've used My in my VB.NET projects, and I don't feel guilty about it. I am primarily a C# guy, but until I transitioned my company to C#, we were a VB shop. In my mind, the My namespace is a nice piece of syntactic sugar. Just as I'm not embarrassed to use C#'s coalesce operator and other sugar, I'm not embarrassed to use VB's sugar, either. (To an extent; I won't use the classic VB functions that .NET still exposes.)

That said, never put anything in that namespace. It's Microsoft's namespace, and just as you wouldn't put anything under System nor Microsoft, don't put anything under My. It will cause confusion later on -- if not for you, then for others who maintain your code. Create your own namespace for your own code.

查看更多
家丑人穷心不美
6楼-- · 2020-04-02 07:23

I don't use it a lot.

查看更多
放我归山
7楼-- · 2020-04-02 07:26

Never used it so far, although I've never actually looked into it either.

I wouldn't advise putting anything into the My namespace yourself, it's much more clear just to lay it out like you would if it were a non-VB framework.

查看更多
登录 后发表回答