C#程序将整数数组转换为字符串数组

使用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