我有一个简单的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 };
}
}
但是在 (Ctrl+Shift+B) 上显示的错误是
无法使用集合初始化程序初始化类型“int”,因为它没有实现“System.Collections.IEnumerable”
我正在使用 vs 2010 和 和 .NET 框架 4
谢谢大家
最佳答案
您缺少括号。像这样:
int[] a = new int[] { 1, 2, 3 };
关于c# - 无法初始化类型 'int' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18307751/