protected global:: 作用
原文:http://blog.csdn.net/awen_q/article/details/4405359
protected global::System.Web.UI.WebControls.TextBox TextBox1; 至于protected是大家都知道是访问修饰符,这里不多做解释。 关键是后面的global::是什么意思呢? 它是命名空间别名限定符 防止名称冲突的,因为如果你也定义(或工程中引用了别人某处定义了)同名空间的类就会出问题。 下面有一个网上的例子: using System; 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); /* 但是,可以通过使用 global::System.Console 避免这一错误,如下所示: */ global::System.Console.WriteLine(number); } } 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/patriot074/archive/2009/02/11/3877613.aspx
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace ConsoleApplication1 7 { 8 9 class TestApp 10 { 11 // Define a new class called 'System' to cause problems. 12 public class System { } 13 // Define a constant called 'Console' to cause more problems. 14 const int Console = 7; 15 const int number = 66; 16 static void Main() 17 { 18 19 Console.WriteLine(number); // Error Accesses TestApp.Console //Console.WriteLine(number); 20 global::System.Console.WriteLine(number); 21 } 22 } 23 }

浙公网安备 33010602011771号