"global::" usage

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • twang090@gmail.com

    #1

    "global::" usage

    I find in other team member's project, they are referencing a type in
    following format
    "
    public static global::ErrorRe port.Descriptio n Description
    = new global::ErrorRe port.Descriptio n();
    "

    I do not understand the usage of "global" here, could anyone please
    clarify its usage and what benift of using that. Thanks in advance.

  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: "global::& quot; usage

    In C#, you can have namespaces and classes which share a name as well as
    have nested namespaces/classes which have are shared, causing ambiguity.

    Using "global::" indicates that the namespace after it will be processed
    from the root level, not using the immediate namespace/class scope for
    resolution.

    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    <twang090@gmail .comwrote in message
    news:1193067379 .827431.22760@z 24g2000prh.goog legroups.com...
    >I find in other team member's project, they are referencing a type in
    following format
    "
    public static global::ErrorRe port.Descriptio n Description
    = new global::ErrorRe port.Descriptio n();
    "
    >
    I do not understand the usage of "global" here, could anyone please
    clarify its usage and what benift of using that. Thanks in advance.
    >

    Comment

    • kentcb@internode.on.net

      #3
      Re: &quot;global::& quot; usage

      See http://msdn2.microsoft.com/en-us/lib...3d(VS.80).aspx. You
      will often see the global:: qualifier in generated code to ensure that
      it is refering to the correct types. I don't think I've ever since it
      used manually - it's rarely necessary. It's unclear from your example
      whether it is actually needed or not. It depends whether there are
      more than one ErrorReport types.

      Regards,
      Kent

      On Oct 22, 4:36 pm, twang...@gmail. com wrote:
      I find in other team member's project, they are referencing a type in
      following format
      "
      public static global::ErrorRe port.Descriptio n Description
      = new global::ErrorRe port.Descriptio n();
      "
      >
      I do not understand the usage of "global" here, could anyone please
      clarify its usage and what benift of using that. Thanks in advance.

      Comment

      • =?Utf-8?B?UGV0ZXIgUml0Y2hpZSBbQyMgTVZQXQ==?=

        #4
        Re: &quot;global::& quot; usage


        "Jon Skeet [C# MVP]" wrote:
        Is there a difference between
        that and the kind of class you can create in C++ or VB.NET?
        The VB language supports classes at the global scope; but the VB.NET IDE
        does not; you must specific a default namespace for a project in which all
        classes and namespaces will be nested. I don't know what the global scope
        resolution operator/keyword is in VB...

        In C++/CLI you can also have managed classes at global scope. In C++ the
        global scope resolution operator is '::', the equivalent of 'global::'. But,
        often Intellisense gets confused with that...

        Comment

        • Mattias Sjögren

          #5
          Re: &quot;global::& quot; usage

          >The VB language supports classes at the global scope; but the VB.NET IDE
          >does not; you must specific a default namespace for a project in which all
          >classes and namespaces will be nested.
          You don't have to specify one, you can leave it blank.


          Mattias

          --
          Mattias Sjögren [C# MVP] mattias @ mvps.org
          http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
          Please reply only to the newsgroup.

          Comment

          • =?Utf-8?B?UGV0ZXIgUml0Y2hpZSBbQyMgTVZQXQ==?=

            #6
            Re: &quot;global::& quot; usage

            I've had it complain that the root namespace can't be empty. But, with some
            projects it does let you have an empty namespace. Interesting...

            --
            Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.

            Microsoft MVP, Visual Developer - Visual C#


            "Mattias Sjögren" wrote:
            The VB language supports classes at the global scope; but the VB.NET IDE
            does not; you must specific a default namespace for a project in which all
            classes and namespaces will be nested.
            >
            You don't have to specify one, you can leave it blank.
            >
            >
            Mattias
            >
            --
            Mattias Sjögren [C# MVP] mattias @ mvps.org
            http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
            Please reply only to the newsgroup.
            >

            Comment

            • =?Utf-8?B?UGV0ZXIgUml0Y2hpZSBbQyMgTVZQXQ==?=

              #7
              Re: &quot;global::& quot; usage

              It appears you can't have an empty root namespace for class library projects
              in VB, but you can for Console/Winform applications. Interesting...

              --
              Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.

              Microsoft MVP, Visual Developer - Visual C#


              "Mattias Sjögren" wrote:
              The VB language supports classes at the global scope; but the VB.NET IDE
              does not; you must specific a default namespace for a project in which all
              classes and namespaces will be nested.
              >
              You don't have to specify one, you can leave it blank.
              >
              >
              Mattias
              >
              --
              Mattias Sjögren [C# MVP] mattias @ mvps.org
              http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
              Please reply only to the newsgroup.
              >

              Comment

              • =?Utf-8?B?UGV0ZXIgUml0Y2hpZSBbQyMgTVZQXQ==?=

                #8
                Re: &quot;global::& quot; usage

                I'm not sure what's different, but I have some VB class library projects not
                allow a blank root namespace and some do. Interesting...

                I'll add that to my list of reasons why I don't like VB...

                --
                Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.

                Microsoft MVP, Visual Developer - Visual C#


                "Mattias Sjögren" wrote:
                The VB language supports classes at the global scope; but the VB.NET IDE
                does not; you must specific a default namespace for a project in which all
                classes and namespaces will be nested.
                >
                You don't have to specify one, you can leave it blank.
                >
                >
                Mattias
                >
                --
                Mattias Sjögren [C# MVP] mattias @ mvps.org
                http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
                Please reply only to the newsgroup.
                >

                Comment

                Working...