如何找到列表字符串的最大值 [英] How can I find largest value of list string

查看:654
本文介绍了如何找到列表字符串的最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有列表int

Hi,

I have list int

List<int> buffer1 = new List<int>();



我在此列表字符串中添加了一些值


I added some values to this list string

buffer1.Add(f);
buffer1.Add(f1);
buffer1.Add(f2);
buffer1.Add(f3);
buffer1.Add(f4);





如何找到列表strin的最大值)



谢谢

John



How can I find the largest value of the list strin)

Thanks
John

推荐答案

你可以使用List.Max()函数来获取最大值。我的情况

You can use List.Max() function to get the max value. I your case
var maxValue = buffer1.Max();


基本上,您将第一个值存储在变量中。然后循环并比较。如果它更大,则存储该值。当你完成整个列表时,你将拥有最大的价值。



Essentially you store the first value in a variable. Then loop through and compare. If it is larger then store that value. By the time you are done going through the whole list you'll have the largest value.

Int32 largestVal = buffer1[0];
foreach (Int32 temp in buffer1)
{
   if (temp > largestVal)
     largestVal = temp;
}


这篇关于如何找到列表字符串的最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆