C#控件台字符(串)读取
1.输入字符:
1int readValue;
2char character;
3readValue = System.Console.Read();
4character = (char) readValue; //隐式类型转换.
5System.Console.Write(character);
2char character;
3readValue = System.Console.Read();
4character = (char) readValue; //隐式类型转换.
5System.Console.Write(character);
2.输入字符串:
(1)方法一:
1string str = Console.ReadLine();
2char[] arr=str.ToCharArray();
3Array.Reverse(arr);
4Console.WriteLine(new string(arr));
2char[] arr=str.ToCharArray();
3Array.Reverse(arr);
4Console.WriteLine(new string(arr));
(2)方法二:
1string myString=Console.ReadLine();
2char[] myChars = myString.ToCharArray();
3for (int i = 0; i < myChars.Length; i++)
4{
5 Console.Write(myChars[myChars.Length-i-1]);
6}
7
2char[] myChars = myString.ToCharArray();
3for (int i = 0; i < myChars.Length; i++)
4{
5 Console.Write(myChars[myChars.Length-i-1]);
6}
7