I want to find, let's say, the minimum element in the list by field, but without cycles. LINQ Min does not return to me an object from the collection, but a field type, which is logical (NO!).
In c ++ there are functions that allow you to pass a function by which to make a comparison, and will return a collection object, which is logical (YES!).
Example:
class A { public int x; public int y; } ... List<A> list = new List<A>(); ... //можно так int min = int.MaxValue; A res; foreach(var it in list) { if( it.x < min ) { min = it.x; res = it; } } //или так(наверно, не проверял) но тут как бы уже два прохода по циклу. int min1 = list.Min(it => it.x); A res1 = list.Where(it => it.x == min1).First(); Is there something like this in C #? External tools cannot be connected.
Thank!