Namespace references in C# vs. VB.Net

后端 未结 3 1438
轮回少年
轮回少年 2021-01-04 21:55

In VB.Net you can do something like the following without any issues... just ignore the fact that this is a pretty useless class :-)


Imports System

Public          


        
相关标签:
3条回答
  • 2021-01-04 22:31

    using directive in C# does not allow this:

    Create a using directive to use the types in a namespace without having to specify the namespace. A using directive does not give you access to any namespaces that are nested in the namespace you specify.

    VB.NET, however, supports somewhat closer behavior with Imports statement:

    The scope of the elements made available by an Imports statement depends on how specific you are when using the Imports statement. For example, if only a namespace is specified, all uniquely named members of that namespace, and members of modules within that namespace, are available without qualification. If both a namespace and the name of an element of that namespace are specified, only the members of that element are available without qualification.

    Reference SO Question

    0 讨论(0)
  • 2021-01-04 22:33

    This is because VB.Net supports partial namespaces; C# does not.

    With Visual Basic, System is imported by default and child namespaces are automatically resolved.

    Read more in this article.

    VB.Net vs C#, Round 2: Partial Namespaces

    0 讨论(0)
  • 2021-01-04 22:52

    you can say System.Collections.Generic.List. that would work.

    I think you need to give the entire list and not omit out the system part.

    ALso you will need to template it with string as in List similar to the List(Of string)

    0 讨论(0)
提交回复
热议问题