Click here to Skip to main content
15,886,753 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a generic list with many lines like that :
Client.add (new client ( "name" , "adress","phone " ........ , a number ));
I have about 100 of these i want to take the value of the number and see the minimum value of it
Posted

Use LINQ Min method.

C#
var a  = new dynamic[] {new {a ="a", n = 10},new {a ="b", n = 5},new {a ="c", n = 6},new {a ="d", n = 2}};
int min = a.Min(x => x.n);
Console.Write(min);
 
Share this answer
 
v3
Comments
BillWoodruff 17-Nov-14 15:59pm    
Are you aware this will not compile for an obvious reason ?
Zoltán Zörgő 17-Nov-14 16:05pm    
Oh, it will! Just paste it in LinqPad, and you will see. I made it there :)
Still, the second row is the answer, the rest is just for demonstration.

Well, I missed a "var" and a semicolon while copying... but now it's complete again...
Manas Bhardwaj 18-Nov-14 6:54am    
Yes +5
C#
int min = Client.Min(client => client.a_number);
[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 17-Nov-14 16:02pm    
That's the way, a 5.
—SA
Manas Bhardwaj 18-Nov-14 6:54am    
Yes +5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900