So, to keep it short, I have this bit of code in which I loop through the results of a string split and add them to a list, if they have not occurred before in the loop. This is the code.
var res = new List<string>();
foreach(string s in input.Split(new[] { ", " },
StringSplitOptions.RemoveEmptyEntries))
{
if(res.All(p => p != s))
res.Add(s);
}
But after I wrote this code, Visual Studio said I could convert part of the loop into LINQ. However, I'm a bit skeptical about whether this'll work or not.
Basically, my question is, would the lambda expressions be executed on each separate loop, or just once in the beginning?
var res = new List<string>();
foreach (string s in input.Split(new[] { ", " },
StringSplitOptions.RemoveEmptyEntries)
.Where(s => res.All(p => p != s)))
{
res.Add(s);
}