我的C#控制台应用程序被用来作为我的C#窗体应用程序登录,问题是,在我的C#控制台应用程序,我一直没能到的方式计算出来ReadLine,而不需要按的Enter,因为我需要检测是否F2还是Enter按然后ReadLine无需用户Enter再次按下。例如,如果我想检测是否F2被按下,我需要等到F2被按下直到我能够ReadLine,希望这个问题的措辞是有意义的,我相信你可以说我很c# 中的“菜鸟”。
我的问题示例:
static void Main()
{
var KP = Console.ReadKey();
if (KP.Key == ConsoleKey.F2)
{
//User Presses F2
}
else if (KP.Key == ConsoleKey.Enter)
{
string UserName = ReadLineWithoutPressingEnter();//Just a example
//ReadLine without needing to press enter again
}
}
Run Code Online (Sandbox Code Playgroud)
感谢您的时间。
有没有办法在函数参数中添加if语句?例如:
static void Main()
{
bool Example = false;
Console.Write((if(!Example){"Example is false"}else{"Example is true"}));
}
//Desired outcome of when the code shown above is
//executed would be for the console to output:
//Example is false
Run Code Online (Sandbox Code Playgroud) 我仍在学习 C++ 并且花了几个小时试图找出一种方法来将一个字节存储在某个内存地址,在我的情况下,所有(几乎所有)内存地址都不是动态的 - 所以地址指向,对于示例变量不会改变。
所以我试图检索存储在已知内存地址的单个字节。例如,让我们说:0x20000
例如,我试图检索的字节是0xEF.
现在我将如何在不使用取消引用运算符的情况下检索字节?所以基本上我需要在0xEF不必声明它是什么类型的数据类型的情况下获取,就像字面上只是物理获取字节一样0xEF。希望这是有道理的,我是个菜鸟:/
我已经尝试了一些东西,但还没有弄清楚如何获得const wchar_t *text(如下所示)传入变量StoreText(如下所示).我究竟做错了什么?
void KeyboardComplete(int localClientNum, const wchar_t *text, unsigned int len)
{
char* StoreText = text; //This is where error occurs
}
Run Code Online (Sandbox Code Playgroud)