Hashtable与ArrayList都可以存储任何类型的数据,但不容易取数据。 1.在键值对集合当中,我们是 […]
分类: c#
题一://翻转字符串s
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
string s = "asdfghjk"; for (int i = s.Length-1; i >= 0;i-- )//遍历的方式倒序输出 { Console.Write(s[i]); } Console.ReadKey(); } 方法二: string s = "asdfghjk"; char[] chs= s.ToCharArray(); for (int i = 0; i < s.Length/2; i++)//首尾交换 { char temp = chs[i]; chs[i] = chs[s.Length - i - 1]; chs[s.Length - i - 1] = temp; } //s=chs.ToString();//错误 s = new string(chs);//字符数组转字符串 不能直接这样转s=chs.ToString() Console.Write(s); Console.ReadKey(); |
注意: 一:字符串数 […]