我正在正确编写代码,但出现错误 - 缺少命名空间或程序集引用。代码有问题还是我遗漏了什么?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
int i = 0;
int sum = 0;
int[] arr = new int[] { 1, 2 };
do
{
{
sum += arr[1];
Console.WriteLine("Wow");
i++;
}
}
while (i < 3);
}
}
}
Error is : Error Cannot initialize type 'int' with a collection initializer because it does not implement 'System.Collections.IEnumerable
最佳答案
我的命名空间以 Console
结尾(即 MyProject.Console
),这搞乱了对 Console.Write
的调用。在这种情况下,写入完全限定名称 System.Console.Write
或更改命名空间。
关于c# - 缺少命名空间或程序集引用时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11964781/