global::在c#中的作用

global 是 C# 2.0 中新增的关键字,理论上说,如果代码写得好的话,根本不需要用到它。

假设你现在写了一个类,名字叫 System。那么当你再在代码里写 System 的时候,编译器就不知道你是要指你写的 System 类还是系统的 System 命名空间,而 System 命名空间已经是根命名空间了,无法再通过完全限名来指定。在以前的 C# 版本中,这就是一个无法解决的问题。现在,可以通过

global::System

来表示 System 根命名空间,而用你自己的

MyNamespace.System

来表示自己的类。


当然,这种情况不应该出现,你不应该写一个名为 System 的类。

实例应用:

[global::System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")]
    
public partial class upMDMSearchForDictDataTypeDefineTableAdapter : global::System.ComponentModel.Component {
        
        
private global::System.Data.SqlClient.SqlDataAdapter _adapter;
        
        
private global::System.Data.SqlClient.SqlConnection _connection;
        
        
private global::System.Data.SqlClient.SqlCommand[] _commandCollection;
        
        
private bool _clearBeforeFill;
        
        [
global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        
public upMDMSearchForDictDataTypeDefineTableAdapter() {
            
this.ClearBeforeFill = true;
        }
        
        [
global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        
private global::System.Data.SqlClient.SqlDataAdapter Adapter {
            
get {
                
if ((this._adapter == null)) {
                    
this.InitAdapter();
                }
                
return this._adapter;
            }
        }
}
原文地址:https://www.cnblogs.com/a311300/p/1672871.html