本文介绍了阅读在C#中的两个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法读取Console.Read()方法的第二个字符。我的意思是我没有得到任何提示读取键盘的第二个字符。任何帮助吗?另外,据我所知,字符是默认的int,但我们仍然从输入读取时需要将其转换为char,是不是?下面的code读取的第一个字符,但终止与第二。
公共静态无效的主要()
{
Console.WriteLine(第一个字符?:);
焦炭firstChar = Convert.ToChar(Console.Read());
Console.WriteLine(第二个字符?:);
焦炭secondChar = Convert.ToChar(Console.Read());
}
解决方案
请参阅的。具体而言,该部分:
I cannot read a second character with Console.Read() method. I mean I don't get any Prompt to read the second character from Keyboard. Any help please? Also, I understand that character is by default an int but we still need to convert it to char when reading from input, is it right? The code below reads the first char but terminates with the second.
public static void Main()
{
Console.WriteLine("The First Character?:");
char firstChar=Convert.ToChar(Console.Read());
Console.WriteLine("The Second Character?:");
char secondChar=Convert.ToChar(Console.Read());
}
解决方案
Please see Console.Read. Specifically, this part:
这篇关于阅读在C#中的两个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!