【发布时间】:2016-10-18 21:57:57
【问题描述】:
我需要创建一个函数来接收一个数组项并反转数组中项的顺序并返回它。
基本上,如果我有一个数组 ['cat', 'dog', 'bird', 'worm'] 函数应该返回一个数组 ['worm','bird','dog','cat'] .
到目前为止,我迷失在函数语言中......我有这个。
//Split a string into an array of substring
string avengersNames = "Thor;Iron Man;Spider-Man;Hulk;Hawk Eye";
//Creat an array to hold substring
string[] heroArray = avengersNames.Split(';');
foreach (string hero in heroArray)
{
Console.WriteLine(hero);
}
//Parameter is Array of items
//At a loss when trying to incorporate an array into this function.
public static string[] heroList = new string[5];
{
}
【问题讨论】:
-
除了知道内置函数之外,请记住
foreach通常有用而通常无用。使用常规的for循环,您不会遇到任何问题!