Cannot we use break statement in a lambda(C#3.0)
Posted
by Newbie
on Stack Overflow
See other posts from Stack Overflow
or by Newbie
Published on 2010-05-18T13:05:49Z
Indexed on
2010/05/18
13:10 UTC
Read the original article
Hit count: 119
c#3.0
Consider this
List<int> intList = new List<int> { 1, 2, 3, 4, 5, 6 };
int j = 0;
intList.ForEach(i =>
{
if (i.Equals(1))
{
j = i;
break;
}
}
);
Throwing error: No enclosing loop out of which to break or continue
But the below works
foreach(int i in intList)
{
j = i; break;
}
Why so. Am I making any mistake.
Thanks
© Stack Overflow or respective owner