C# 程序,从方法中返回数组
在 Join 方法下调用一个方法,以连接单词 −
string.Join(" ", display())
现在设置一个字符串数组 −
string[] str = new string[5];
添加单个元素 −
str[0] = "My"; str[1] = "name"; str[2] = "is"; str[3] = "Brad"; str[4] = "Pitt";
并从该方法返回相同的字符串数组 −
return str;
完整的代码如下 −
示例
using System; public class Demo { public static void Main() { Console.WriteLine(string.Join(" ", display())); } static string[] display() { string[] str = new string[5]; // string array elements str[0] = "My"; str[1] = "name"; str[2] = "is"; str[3] = "Brad"; str[4] = "Pitt"; return str; } }
输出
My name is Brad Pitt
广告