字符和字符串的关系:字符串可以看成是只读字符数组
来源:互联网 发布:怎样优化亚马逊关键词 编辑:程序博客网 时间:2024/05/16 14:49
using System;namespace ConsoleApplication2{ class Program { /** * 字符和字符串的关系:字符串可以看成是只读字符数组 */ static void Main(string[] args) { char c = 'a'; char c2 = '中'; // char c3 = 'fdf'; error // char c4 = ''; error string s = "a"; string s2 = ""; string s3 = "fdf"; string s4 = "我是中国人"; char s5 = s4[0]; Console.WriteLine(s5); // s4[0] = '你'; error.他是只读的 Console.WriteLine("------------------------------"); foreach(char s44 in s4) { Console.WriteLine(s44); } Console.WriteLine("------------------------------"); for (int i = s4.Length - 1; i >= 0; i -- ) { Console.WriteLine(s4[i]); } Console.ReadKey(); } }}