get out of foreach statement c#
foreach (string s in sList)
{
if (s.equals("ok"))
{
break; // get out of the loop
}
}
get out of foreach statement c#
foreach (string s in sList)
{
if (s.equals("ok"))
{
break; // get out of the loop
}
}
c# break from foreach method
list.Foreach((item) => {
// You cannot break from here beacuse of the structure of the method.
// Underneath is they way the meothd is tructured and a break is not allowed.
//public static ForEach<T>(this IEnumerable<T> input, Action<T> action)
//{
//foreach(var i in input)
// action(i);
//}
});
// You have to convert your code into the traditional foreach:
foreach(var item in list) {
// Your code here
break; // <- As you can see you can break here.
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us