两个值求最大最小:
1 2 3 4 |
int a=12; int b=13; int max=Math.Max(a,b);//Math.Max()不能比较datetime int min=a<b?a:b; |
三个值求最大最小:
1 2 3 4 5 |
int a=12; int b=13; int c=14; int max=a>b?(a>c?a:c):(b>c?b:c); int min=a<b?(a<c?a:c):(b<c?b:c); |
多个值求最大最小:
1 2 3 4 5 6 |
int a = 12; int b = 13; int c = 14; int d = 15; int max = new List<int> { a, b, c, d }.Max(); int min = new List<int> { a, b, c, d }.Min(); |
© 2018, ITJOY.NET. 版权所有. 如未注明,均为原创,转载请注明出处。