C# finding the shortest and longest word in a array

后端 未结 8 1260
小蘑菇
小蘑菇 2021-01-15 04:32

I am trying to find the shortest and longest string value based on length and im getting stuck. As of now the script exits after the writeline. I think the code needs some h

8条回答
  •  时光说笑
    2021-01-15 05:09

    Linq is the way to go here to make your life a lot easier...

    var sorted=word.OrderBy(n => n.Length);
    var shortest = sorted.FirstOrDefault();
    var longest = sorted.LastOrDefault();
    

提交回复
热议问题