输入一段字符串,通过foreach循环将用户输入的字符串赋值给一个字符数组
Console.WriteLine("请输入一段字符串:"); string str = Console.ReadLine(); char[] chs = new char[str.Length]; int i = 0; //将字符串转成数组; foreach (var item in str) { chs[i] = item; i++; } foreach (var item in chs) { Console.WriteLine(item); } Console.ReadKey();