在List< string>中获得最高的可用号码. [英] Getting highest available number in a List<string>

查看:40
本文介绍了在List< string>中获得最高的可用号码.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在List<string>

vs0,vs1,vs2,vs3,vs4,vs5,... vs(n)

vs0, vs1, vs2, vs3, vs4, vs5, ... vs(n)

在我的列表中,它们没有排序并且是随机的.我想获取其中具有最高int的字符串.然后将字符串中的数字输入int var.

In my list, they are not sorted and are random. I want to get the string which has the highest int in it. And then get the number out of that string into a int var.

最佳和最快的方法是什么?

What is the best and fastest way do this?

推荐答案

var max = myList.OrderByDescending(v => int.Parse(v.Substring(2))).First();

或者如果您需要最高的整数

or if you need the highest int

var max = myList.Select(v => int.Parse(v.Substring(2))).Max();

这篇关于在List&lt; string&gt;中获得最高的可用号码.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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