Я могу представить себе такой сценарий примерно так:
Код: Выделить всё
var myList = new [] { 1,2,3,4,5 }
var result = myList
.MyAwesomeSpecialWhereMethod(i => i % 2 == 0) // results in an object that has 2 lists, one containing successes and one containing failures
.SelectSuccess(i => $"{i} is even") // modifies the success list into a list of strings
.SelectFailure(i => $"{i} is odd") // modifies the failure list into a list of strings
.Collect((success, failure) => success.Union(failure)) // aggregates the success and failure list using my lambda
Console.WriteLine(result)
Код: Выделить всё
["2 is even","4 is even","1 is odd","3 is odd","5 is odd"] // (because I didn't bother sorting)
Код: Выделить всё
foreach (var i in myList){
if (i%2 == 0){
evens.Add(i);
} else {
odds.Add(i);
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... ion-and-se
Мобильная версия