c#中将整数转化为字符串
Given a string and we have to convert it into character array in C#.
给定一个字符串,我们必须将其转换为C#中的字符数组。
将字符串转换为char [] (Converting string to char[])
To convert a given string in char[] (character array), we use String.ToCharArray() method of String class, it is called with this string and returns a characters array, it converts characters of the string to an array of Unicode characters.
要在char [] (字符数组)中转换给定的字符串,我们使用String类的String.ToCharArray()方法 ,用此字符串调用它并返回一个字符数组,它将字符串中的字符转换为Unicode字符数组。
Example:
例:
Input:
string str = "Hello world!";
Function call:
char[] char_arr = str.ToCharArray();
Output:
char_arr: H e l l o w o r l d !
C#使用String.ToCharArray()方法将字符串转换为字符数组的示例 (C# Example to convert string to characters array using String.ToCharArray() method)
using System;
using System.Text;
namespace Test
{
class Program
{
static void Main(string[] args)
{
//string variable
string str = "Hello world!";
//converting string to char[]
char[] char_arr = str.ToCharArray();
Console.WriteLine("str: " + str);
//printing char[]
Console.WriteLine("char_arr...");
foreach (char item in char_arr)
{
Console.Write(item + " ");
}
Console.WriteLine();
//printing types of string & char[]
Console.WriteLine("Type of str: " + str.GetType());
Console.WriteLine("Type of char_arr: " + char_arr.GetType());
//hit ENTER to exit
Console.ReadLine();
}
}
}
Output
输出量
str: Hello world!
char_arr...
H e l l o w o r l d !
Type of str: System.String
Type of char_arr: System.Char[]
翻译自: https://www.includehelp.com/dot-net/convert-string-to-character-array-in-c-sharp.aspx
c#中将整数转化为字符串