I have the following strings in a List<string>
vs0, vs1, vs2, vs3, vs4, vs5, ... vs(n)
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With