C# 求数组中单词最小和最大长度的最短方法
我有以下数组C# 求数组中单词最小和最大长度的最短方法,c#,lambda,C#,Lambda,我有以下数组 string[] words = { "cherry", "apple", "blueberry", "banana", "mango", "orange", "pineapple" }; 我想找到字母表的Max和Min编号。e、 g.Max=9(菠萝)和Min=5(苹果) 哪种方法最短。您可以使用和方法: 您可以使用和方法: 最有效的方法是简单地循环字符串: int min = Int32.MaxValue; int max = 0; foreach (s in words)
string[] words = { "cherry", "apple", "blueberry", "banana", "mango", "orange", "pineapple" };
我想找到字母表的Max
和Min
编号。e、 g.Max=9(菠萝)和Min=5(苹果)
哪种方法最短。您可以使用和方法:
您可以使用和方法:
最有效的方法是简单地循环字符串:
int min = Int32.MaxValue;
int max = 0;
foreach (s in words) {
min = Math.Min(min, s.Length);
max = Math.Max(max, s.Length);
}
最有效的方法是简单地循环字符串:
int min = Int32.MaxValue;
int max = 0;
foreach (s in words) {
min = Math.Min(min, s.Length);
max = Math.Max(max, s.Length);
}
美丽的。我甚至不知道你可以用C来表达功能性的东西,真漂亮。我甚至不知道你可以用C来表达这样的函数。