无法初始化类型'int'错误

Roh*_*hit 2 c# console-application visual-studio-2010

我在C#中有一个简单的代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyProject
{
  public static class Class1
  {
    public static int[] Iparray = new int { 12, 9, 4, 99, 120, 1, 3, 10 };
  }
}
Run Code Online (Sandbox Code Playgroud)

但是在(Ctrl+ Shift+ B)上显示的错误是

Cannot initialize type 'int' with a collection initializer because it does not implement 'System.Collections.IEnumerable'

我正在使用vs 2010和.NET framework 4

谢谢你们

Art*_*ess 5

你缺少括号.像这样:

int[] a = new int[] { 1, 2, 3 };
Run Code Online (Sandbox Code Playgroud)