gpt4 book ai didi

c# - 查找数组中单词的最小和最大长度的最短方法

转载 作者:太空宇宙 更新时间:2023-11-03 17:23:16 27 4
gpt4 key购买 nike

我有以下数组

string[] words = { "cherry", "apple", "blueberry", "banana", "mango", "orange", "pineapple" };

我想找到 MaxMin 号。的字母表。例如Max = 9(菠萝)和 Min = 5(苹果)

这是最短的方法。

最佳答案

您可以使用 MinMax方法:

var min = words.Min(w=> w.Length);  // 5
var max = words.Max(w=> w.Length); // 9

关于c# - 查找数组中单词的最小和最大长度的最短方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1304152/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com