- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace test01
- {
- class Program
- {
- //怎么将一个 string =" abcdefg";的每一个字符赋给一个char[]中呢
- static void Main(string[] args)
- {
- string a = "abcdefg";
- char[] arry=new char[a.Length];
- //将字符串中每个元素遍历储存到char数组
- for (int i = 0; i < a.Length;i++ )
- {
- arry[i]=a[i];
- }
- //遍历输出char数组中每个元素
- for (int i = 0; i < arry.Length;i++ )
- {
- Console.WriteLine("a{0}={1}",i+1,arry[i]);
- }
- Console.ReadKey();
- }
- }
- }
复制代码 |