C# 程序将整数数组转换为字符串数组
csharpprogrammingserver side programming更新于 2025/9/17 5:33:00
使用 ConvertAll 方法将整数数组转换为字符串数组。
设置一个整数数组 −
int[] intArray = new int[5]; // 具有 5 个元素的整数数组 intArray[0] = 15; intArray[1] = 30; intArray[2] = 44; intArray[3] = 50; intArray[4] = 66;
现在使用 Array.ConvertAll() 方法将整数数组转换为字符串数组 −
Array.ConvertAll(intArray, ele => ele.ToString());
让我们看看完整的代码 −
示例
using System;
using System.Text;
public class Demo {
public static void Main() {
int[] intArray = new int[5];
// 包含 5 个元素的整数数组
intArray[0] = 15;
intArray[1] = 30;
intArray[2] = 44;
intArray[3] = 50;
intArray[4] = 66;
string[] strArray = Array.ConvertAll(intArray, ele => ele.ToString());
Console.WriteLine(string.Join("|", strArray));
}
}
输出
15|30|44|50|66

