[置顶] 看到这样的 语句colAlias::Hashtable 你别晕( 命名空间别名限定符)

我一直看到这样的语句就感觉头疼,这个东西到底是神马意思呢?

今天msdn了一下原来这个东西学名  命名空间别名限定符

 当成员可能被同名的其他实体隐藏时,可以使用这种方式。

using colAlias = System.Collections;
namespace System
{
    class TestClass
    {
        static void Main()
        {
            // Searching the alias:
            colAlias::Hashtable test = new colAlias::Hashtable();

            // Add items to the table.
            test.Add("A", "1");
            test.Add("B", "2");
            test.Add("C", "3");

            foreach (string name in test.Keys)
            {
                // Seaching the gloabal namespace:
                global::System.Console.WriteLine(name + " " + test[name]);
            }
        }
    }
}


遇见了就不要错过
原文地址:https://www.cnblogs.com/Traner/p/2819921.html