What is "global::" in C#?

Asked

Viewed 151 times

9

I was editing a source code for an application I’m writing in C#, which uses GTK+.

I have some knowledge of C#, but did not understand why some variables were written when I mounted the UI in "drag and drop" with the global:: before the names.

See the code snippet:

private Gtk.VBox vbox2;

private global::Gtk.VBox vbox3;

private global::Gtk.Label tituloLogin;

private global::Gtk.Entry entry1;

private global::Gtk.Entry entry2;

What’s this one for global::? What does it mean?

1 answer

9


global:: refers to the global namespace. For example, you can reset the class System, look at:

class foo
{
    class System
    {

    }    
}

There, for example, if you want to use Console.WriteLine() in that scope, without conflict, you use:

global::System.Console.WriteLine("teste");

I based my answer on this here.

  • 1

    A tip, beware of spacing in sentences, 4 spaces the site automatically formats as code.

  • Aaaaah thank you! I’ve had trouble with that again

  • 1

    Only complementing, the equivalent in VB.NET would be Global.System.Console.WriteLine().

Browser other questions tagged

You are not signed in. Login or sign up in order to post.