Due to the fact that you are changing โbeyond the scope of the question,โ I am going to ask what exactly the OP is trying to accomplish.
This code tries to determine if an integer (1) exists anywhere in the list. But it seems clear to me that the above code is just a demo, not a real problem.
Using "ForEach" to iterate through a list to determine if something in the list is the wrong way around this. Instead, using one of the many Find features is a better approach.
For example, with the original OP code:
j = intList.Find(i => i.Equals(1));
This will do the same as the above proposed code. It will iterate over the list by list (and, if possible), return the lambda value to "j" and break earlier.
intList.Exists(i => i.Equals(1));
Will do the same effectively. It will iterate over the list and return TRUE if it can find if 1 exists and break before. (otherwise, iterates over the entire list and returns FALSE.)
intList.FindIndex(i => i.Equals(1));
Will return the FIRST index position that matches the lambda. (again, if possible, early early)
intList.FindAll(i => i.Equals(1));
Returns an auxiliary list of all elements in intList that match the lambda expression. (Naturally, you need to iterate over the entire list, regardless ...)
Newbie: Is there a reason you cannot use any of these built-in methods? Just curious how I would like to help.
Greetings.