Reputation: 2862
In our studying materials we have an example
public static IEnumerable<int> OddNums(int n)
{
int i = –1;
while (i < n – 1)
{
i += 2;
yield return i;
}
}
static void Main(string[] args)
{
foreach (int i in OddNums(10))
Console.WriteLine("{0} ", i);
}
However it throws errors on lines
int i = –1;
while (i < n – 1)
What is wrong?
Upvotes: 1
Views: 91
Reputation: 2980
Its hyphen instead of minus ...
Replace it by minus here:
int i = -1;
and here:
while (i < n - 1)
Upvotes: 1
Reputation: 172588
In your code you are expecting -
to be a minus sign which eventually seems to be a – hyphen
Try to change that by deleting it and then typing it again.
while (i < n - 1)
Upvotes: 1