can I do this without looping through the whole list?
List<string> responseLines = new List<string>();
the list is then filled with around 300 lines of text.
next I want to search the list and create a second list of all lines that either start with “abc” or contain “xyz”.
I know I can do a for each but is there a better / faster way?
You could use LINQ. This is no different performance-wise to using
foreach— that’s pretty much what it does behind the scenes — but you might prefer the syntax:(If you’re happy dealing with an
IEnumerable<string>rather thanList<string>then you can omit the finalToListcall.)