C# CopyTo() 方法用于从字符串中的指定位置复制指定数量的字符。它将这个字符串的字符复制到一个 char 数组中。
public void CopyTo(int index, char[] ch, int start, int end)
index:整数类型参数。它是字符串的索引。
ch:它是一个char类型的数组。
start: char 类型数组的起始索引。
end: char 类型数组的结束索引。
using System; public class StringExample { public static void Main(string[] args) { string s1 = "Hello C#, How Are You?"; char[] ch = new char[15]; s1.CopyTo(10,ch,0,12); Console.WriteLine(ch); } }
输出:
How Are You?