Find the minimum values ​​among 5 integers?

I need to find a minimum of 5 integer values. I used the else expression to compare. So it doesn’t look good. that is, the code is very long. I do not know how to reduce code complexity. can someone help me?

Regards, Karthi

+5
source share
3 answers

Check out the Min LINQ method.

+5
source

You can use the method Minfrom LINQ:

var list = new[] {1, 2, 3, 4, 5};
int min = list.Min();

Here is the LINQ list Minyou can find:

http://msdn.microsoft.com/en-us/library/system.linq.enumerable.min.aspx

+9
source

Math.Min :

int min = Math.Min(Math.Min(Math.Min(Math.Min(n1, n2) ,n3), n4), n5);

, ( ), :

int min = new int[]{ n1, n2, n3, n4, n5}.Min();

int min = new SortedSet<int>() { n1, n2, n3, n4, n5 }[0];
+6

All Articles