共用方式為


編譯器錯誤 CS0038

更新:2007 年 11 月

錯誤訊息

無法存取外部型別 'type1' 的非靜態成員 (透過巢狀型別 'type2')

類別的欄位並未自動提供給巢狀類別 (Nested Class) 使用。欄位必須是 靜態,才可供巢狀類別使用。否則,您必須建立外部類別的執行個體。如需詳細資訊,請參閱巢狀型別 (C# 程式設計手冊)

下列範例會產生 CS0038:

// CS0038.cs
class OuterClass
{
   public int count;
   // try the following line instead
   // public static int count;

   class InnerClass
   {
      void func()
      {
         // or, create an instance
         // OuterClass class_inst = new OuterClass();
         // int count2 = class_inst.count;
         int count2 = count;   // CS0038
      }
   }

   public static void Main()
   {
   }
}