I am writing the code right, but getting error – missing namespace or assembly reference.Is there something wrong with the code or I am missing something?
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
Don’t start with this assumption. Always start with the assumption that the compiler is correct, and your code is wrong.
You haven’t shown any
usingdirectives. In this case all you need is(Either at the very top of your code or within the
namespacedeclaration.)or change your
WriteLinecall to:If that doesn’t fix it (or if you’ve already got such a
usingdirective but forgot to include it), then your project is probably somewhat broken – it’s not like you’re using any exotic types.