<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>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # Compiler Error CS0120 非靜態的字段、方法或屬性“member”要求對象引用 必須首先創建對象實例,才能使用非靜態的字段、方法或屬性。有關靜態方法的更多信息,請參見[靜態類和靜態類成員(C# 編程指南)](https://msdn.microsoft.com/zh-cn/library/79b3xss3.aspx)。有關創建類的實例的更多信息,請參見[實例構造函數(C# 編程指南)](https://msdn.microsoft.com/zh-cn/library/k6sa6h87.aspx)。 下面的示例生成 CS0120: ``` // CS0120_1.cs public class MyClass { // Non-static field public int i; // Non-static method public void f(){} // Non-static property int Prop { get { return 1; } } public static void Main() { i = 10; // CS0120 f(); // CS0120 int p = Prop; // CS0120 // try the following lines instead // MyClass mc = new MyClass(); // mc.i = 10; // mc.f(); // int p = mc.Prop; } } ``` 如果從靜態方法調用非靜態方法,也會生成 CS0120,如下所示: ``` // CS0120_2.cs // CS0120 expected using System; public class MyClass { public static void Main() { TestCall(); // CS0120 // To call a non-static method from Main, // first create an instance of the class. // Use the following two lines instead: // MyClass anInstanceofMyClass = new MyClass(); // anInstanceofMyClass.TestCall(); } public void TestCall() { } } ``` 同樣,靜態方法不能調用實例方法,除非顯式給它提供了類的實例,如下所示: ``` // CS0120_3.cs using System; public class MyClass { public static void Main() { do_it("Hello There"); // CS0120 } private void do_it(string sText) // You could also add the keyword static to the method definition: // private static void do_it(string sText) { Console.WriteLine(sText); } } ``` ## 請參閱 [類和結構(C# 編程指南)](https://msdn.microsoft.com/zh-cn/library/ms173109.aspx)
                  <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>

                              哎呀哎呀视频在线观看