Hi guys,
I have recently switched over my coding from VB.NET to C#. Overall, everything is just fine. However, I'm a little puzzled over how namespaces work in C#. I have heard that they are much better, but best I can tell they simply seem stricter. (Or is this why they are better?)
The two things that I've noticed are:
(1) You cannot import a class (type) name as part of a 'using' import. This is not a big deal, but it does let VB.NET access enum fields directly without requiring the enum type name as a prefix. This is nice. On the other hand, this would allow any static method to be called without the type name. This could be good in that you could create methods that look like keywords (you can do this in VB), but I can also see why C# would want to prevent this.
(2) You cannot seem to import a partial-name. This part is what I'm most confused about. For example, in VB I can import 'System.Windows' and then later can call 'Forms.MessageBox.Show("foo")'. In C# however, it seems a bit more all-or-nothing. I cannot imports 'System.Windows'; it seems that I can either import 'System.Windows.Forms' as a whole, or not at all.
In general, it seems that if the namespace only contains other namespaces, but no types, I cannot import it -- I can only import a full path to a namespace that does contain at least one type. Or am I doing something wrong?
Any thoughts or help here is much appreciated...
Mike
I have recently switched over my coding from VB.NET to C#. Overall, everything is just fine. However, I'm a little puzzled over how namespaces work in C#. I have heard that they are much better, but best I can tell they simply seem stricter. (Or is this why they are better?)
The two things that I've noticed are:
(1) You cannot import a class (type) name as part of a 'using' import. This is not a big deal, but it does let VB.NET access enum fields directly without requiring the enum type name as a prefix. This is nice. On the other hand, this would allow any static method to be called without the type name. This could be good in that you could create methods that look like keywords (you can do this in VB), but I can also see why C# would want to prevent this.
(2) You cannot seem to import a partial-name. This part is what I'm most confused about. For example, in VB I can import 'System.Windows' and then later can call 'Forms.MessageBox.Show("foo")'. In C# however, it seems a bit more all-or-nothing. I cannot imports 'System.Windows'; it seems that I can either import 'System.Windows.Forms' as a whole, or not at all.
In general, it seems that if the namespace only contains other namespaces, but no types, I cannot import it -- I can only import a full path to a namespace that does contain at least one type. Or am I doing something wrong?
Any thoughts or help here is much appreciated...
Mike