Compiler Error CS0650

错误的数组声明符:若要声明托管数组,秩说明符应位于变量的标识符之前。若要声明固定大小缓冲区字段,应在字段类型之前使用 fixed 关键字。

数组未正确声明。在 C# 中,与 C 和 C++ 中不同,方括号放在类型(而不是变量名)后面。并且,请注意固定大小缓冲区的语法与数组的语法不同。

下面的代码示例生成 CS0650。

// CS0650.cs
public class MyClass
{
   public static void Main()
   {
// Generates CS0650\. Incorrect array declaration syntax:
      int myarray[2];   

      // Correct declaration.
      int[] myarray2;

      // Declaration and initialization in one statement
      int[] myArray3= new int[2] {1,2}

      // Access an array element.
      myarray3[0] = 0;
    }
}

下面的示例演示如何在创建固定大小缓冲区时使用 fixed 关键字:

// This code must appear in an unsafe block. 
public struct MyArray 
{
    public fixed char pathName[128];
}

请参阅

固定大小的缓冲区(C# 编程指南)

fixed 语句(C# 参考)

数组(C# 编程指南)