Y a-t-il une `` fonction pour cela est ou devrait-on le coder soi-même comme ceci:
Réponses
Trop de publicités?
Dani
Points
13077
Javad_Amiry
Points
9003
var list = new List<string>(); // or string[] or any
list.Add("a");
list.Add("ccc");
list.Add("bb");
list.Add("eeeee");
list.Add("dddd");
// max-length
var length = list.Max(s => s.Length);
// biggest one
var biggest = list.FirstOrDefault(s => s.Length == length);
// if there is more that one by equal length
var biggestList = list.Where(s => s.Length == length);
// by ordering list
var biggest = list.OrderByDescending(s => s.Length).FirstOrDefault();
// biggest-list by LINQ
var bigList2 = from s in list where s.Length == list.Max(a => a.Length) select s;
// biggest by LINQ
var biggest2 = bigList2.FirstOrDefault();
Eric Lippert
Points
300275
Sudharshan Kalale
Points
31