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];
//字符串数组元素
str[0] = "My";
str[1] = "name";
str[2] = "is";
str[3] = "Brad";
str[4] = "Pitt";
return str;
}
}输出结果
My name is Brad Pitt
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短