Iβll talk a little about Timβs answer and show you a way to do a few extra things in your LINQ queries.
You can expand the logic inside your Where clause to perform some additional processes that can make your code more readable. That would be good for something small:
var novas = linhas.Where(l => { var parts = l.Split(':'); return parts.Length > 1 ? parts[1] == "def" : false; });
If you need multiple statements, you can wrap the body of your sentence in braces, but then you need the return keyword.
Alternatively, if you have a lot of information that will do something inline as unreadable, you can also use a separate method in your request.
public void FindTheStringImLookingFor() { var linhas = new List<string>(); linhas.Add("123;abc"); linhas.Add("456;def"); linhas.Add("789;ghi"); linhas.Add("chocolate"); var words = linhas.Where(GetTheStringIWant); } private bool GetTheStringIWant(string s) { var parts = s.Split(':');
source share