ToArray():
//
// 摘要:
// 从 System.Collections.Generic.IEnumerable<T> 创建一个数组。
//
// 参数:
// source:
// 要从其创建数组的 System.Collections.Generic.IEnumerable<T>。
//
// 类型参数:
// TSource:
// source 中的元素的类型。
//
// 返回结果:
// 一个包含输入序列中的元素的数组。
//
// 异常:
// System.ArgumentNullException:
// source 为 null。
public static TSource[] ToArray<TSource>(this IEnumerable<TSource> source);
例:将数组转换成字符串
string str = "abcde";
char[] strs = str.ToArray();
foreach (char item in strs)
{
Console.WriteLine(item);
}
//模范ToArray()的实现
char[] strs=new char[str.Length];
for (int i = 0; i < str.Length; i++)
{
strs[i] = str[i];
}