What is the difference between "global::System" and "System" in .NET?

.net, namespaces, visual-studio-2008

Solution

The :: operator is called a Namespace Alias Qualifier.

 global::System.Data.DataTable 

is the same as:

 System.Data.DataTable

Visual Studio 2008 added it to the designer generated code to avoid ambigious reference issues that occasionally happened when people created classes named System...For example:

class TestApp
{
    // Define a new class called 'System' to cause problems.
    public class System { }

    // Define a constant called 'Console' to cause more problems.
    const int Console = 7;
    const int number = 66;

    static void Main()
    {
        // Error  Accesses TestApp.Console
        //Console.WriteLine(number);
    }
}

However:

global::System.Console.Writeline("This works");

For further reading:

http://msdn.microsoft.com/en-us/library/c3ay4x3d(VS.80).aspx

Problem

I just upgraded a VS 2005 project to VS 2008 and was examining the changes. I noticed one of the .Designer.cs files had changed significantly. The majority of the changes were simply replacements of System with global::System. For example, ``` protected override System.Data.DataTable CreateInstance() ``` became ``` protected override global::System.Data.DataTable CreateInstance() ``` What's going on here?

Original source