Share via


컴파일러 오류 CS0038

업데이트: 2007년 11월

오류 메시지

'type2' 중첩 형식을 통해 'type1' 외부 형식의 비정적 멤버에 액세스할 수 없습니다.
Cannot access a nonstatic member of outer type 'type1' via nested type 'type2'

클래스 안의 필드는 중첩 클래스에 자동으로 사용할 수 없습니다. 중첩 클래스에서 사용하려면 필드가 static이거나 외부 클래스의 인스턴스를 만들어야 합니다. 자세한 내용은 중첩 형식(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()
   {
   }
}