컴파일러 오류 CS1708

고정 크기 버퍼는 지역 변수나 필드를 통해서만 액세스할 수 있습니다.

C# 2.0의 새로운 기능은 struct 내부에서 인라인 배열을 정의하는 기능입니다. 이러한 배열은 지역 변수나 필드를 통해서만 액세스할 수 있으며, 식의 왼쪽에서 중간 값으로 참조할 수 없습니다. 또한, static 또는 readonly인 필드를 통해 배열에 액세스할 수 없습니다.

이 오류를 해결하려면 배열 변수를 정의하고 인라인 배열을 변수에 할당합니다. 또는 인라인 배열을 나타내는 필드에서 static 또는 readonly 한정자를 제거합니다.

예시

다음 샘플에서는 CS1708을 생성합니다.

// CS1708.cs  
// compile with: /unsafe  
using System;  
  
unsafe public struct S  
{  
    public fixed char name[10];  
}  
  
public unsafe class C  
{  
    public S UnsafeMethod()  
    {  
        S myS = new S();  
        return myS;  
    }  
  
    static void Main()  
    {  
        C myC = new C();  
        myC.UnsafeMethod().name[3] = 'a';  // CS1708  
        // Uncomment the following 2 lines to resolve:  
        // S myS = myC.UnsafeMethod();  
        // myS.name[3] = 'a';  
  
        // The field cannot be static.  
        C._s1.name[3] = 'a';  // CS1708  
  
        // The field cannot be readonly.  
        myC._s2.name[3] = 'a';  // CS1708  
    }  
  
    static readonly S _s1;  
    public readonly S _s2;  
}