c# - how can I convert this foreach loop to linq? -
i'm new linq. want convert these lines of code linq lambda expression, if makes sense how can achieve?
foreach (var type in essay.text) { string text = $"{"here result"}\n{method(type)}"; if (text.length <= 20 && !string.isnullorempty(method(type))) { essay.total += text; } }
with of resharper:
essay.total = string.concat( essay.text.select(type => new {type, text = $"{"here result"}\n{method(type)}"}) .where(@t => @t.text.length <= 20 && !string.isnullorempty(method(@t.type))) .select(@t => @t.text) );
Comments
Post a Comment