C# 程序将整数数组转换为字符串数组
使用 ConvertAll 方法可将整数数组转换为字符串数组。
设置一个整数数组 −
int[] intArray = new int[5]; // Integer array with 5 elements 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];
// Integer array with 5 elements
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
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP