// Online C# Editor for free
// Write, Edit and Run your C# code using C# Online Compiler
using System;
using System.Linq;
using System.Collections.Generic;
public class HelloWorld
{
public static void Main(string[] args)
{
List<test> testlist = new List<test>();
testlist.Add(new test { id = 5});
testlist.Add(new test { id = 7});
testlist.Add(new test { id = 2});
testlist.Add(new test { id = 8});
//find the min
var min = testlist.Min(x=>x.id);
//get the object with min component
var y = testlist.Where(x=>x.id == min).FirstOrDefault();
Console.WriteLine ($"The min is {min} {y} {y.id}");
}
public class test {
public int id { get;set;}
}
}
Output:
The min is 2 HelloWorld+test 2
NOTE: {y} prints "HelloWorld+test" which is the object hierarchy of parent class and contained class.