源码:找出数组中最长的字符串
public IActionResult Index()
{
string[] names = { "马龙", "迈克尔乔丹", "雷吉米勒", "蒂姆邓肯", "科比布莱恩特"};
string max = GetName(names);
Console.WriteLine(max);
return View();
}
定义方法:
public static string GetName(string[] n)
{
string max = n[0];
for (int i = 0; i < n.Length; i++)
{
if (n[i].Length>max.Length) {
max = n[i];
}
}
return max;
}
文章
视频
文件