<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # C# 命名空間(Namespace) **命名空間**的設計目的是為了提供一種讓一組名稱與其他名稱分隔開的方式。在一個命名空間中聲明的類的名稱與另一個命名空間中聲明的相同的類的名稱不沖突。 ## 定義命名空間 命名空間的定義是以關鍵字 **namespace** 開始,后跟命名空間的名稱,如下所示: ``` namespace namespace_name { // 代碼聲明 } ``` 為了調用支持命名空間版本的函數或變量,會把命名空間的名稱置于前面,如下所示: ``` namespace_name.item_name; ``` 下面的程序演示了命名空間的用法: ``` using System; namespace first_space { class namespace_cl { public void func() { Console.WriteLine("Inside first_space"); } } } namespace second_space { class namespace_cl { public void func() { Console.WriteLine("Inside second_space"); } } } class TestClass { static void Main(string[] args) { first_space.namespace_cl fc = new first_space.namespace_cl(); second_space.namespace_cl sc = new second_space.namespace_cl(); fc.func(); sc.func(); Console.ReadKey(); } } ``` 當上面的代碼被編譯和執行時,它會產生下列結果: ``` Inside first_space Inside second_space ``` ## _using_ 關鍵字 **using** 關鍵字表明程序使用的是給定命名空間中的名稱。例如,我們在程序中使用 **System** 命名空間,其中定義了類 Console。我們可以只寫: ``` Console.WriteLine ("Hello there"); ``` 我們可以寫完全限定名稱,如下: ``` System.Console.WriteLine("Hello there"); ``` 您也可以使用 **using** 命名空間指令,這樣在使用的時候就不用在前面加上命名空間名稱。該指令告訴編譯器隨后的代碼使用了指定命名空間中的名稱。下面的代碼延時了命名空間的應用。 讓我們使用 using 指定重寫上面的實例: ``` using System; using first_space; using second_space; namespace first_space { class abc { public void func() { Console.WriteLine("Inside first_space"); } } } namespace second_space { class efg { public void func() { Console.WriteLine("Inside second_space"); } } } class TestClass { static void Main(string[] args) { abc fc = new abc(); efg sc = new efg(); fc.func(); sc.func(); Console.ReadKey(); } } ``` 當上面的代碼被編譯和執行時,它會產生下列結果: ``` Inside first_space Inside second_space ``` ## 嵌套命名空間 命名空間可以被嵌套,即您可以在一個命名空間內定義另一個命名空間,如下所示: ``` namespace namespace_name1 { // 代碼聲明 namespace namespace_name2 { // 代碼聲明 } } ``` 您可以使用點(.)運算符訪問嵌套的命名空間的成員,如下所示: ``` using System; using first_space; using first_space.second_space; namespace first_space { class abc { public void func() { Console.WriteLine("Inside first_space"); } } namespace second_space { class efg { public void func() { Console.WriteLine("Inside second_space"); } } } } class TestClass { static void Main(string[] args) { abc fc = new abc(); efg sc = new efg(); fc.func(); sc.func(); Console.ReadKey(); } } ``` 當上面的代碼被編譯和執行時,它會產生下列結果: ``` Inside first_space Inside second_space ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看