C# finding the shortest and longest word in a array

后端 未结 8 1256
小蘑菇
小蘑菇 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:17

    If you use LINQ, using Max/Min method is a better way than sorting.

    var longest = word.Max(s=>s.Length);
    var shortest = word.Min(s=>s.Length);
    

提交回复
热议问题