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 }
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决