小编C0d*_*1ng的帖子

c# 控制台:如何在无需按 [Enter] 的情况下读取行

我的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)




感谢您的时间。

c# console-application

6
推荐指数
1
解决办法
5330
查看次数

我可以在参数中添加if语句吗?

有没有办法在函数参数中添加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#

5
推荐指数
2
解决办法
72
查看次数

从内存地址获取字节?

我仍在学习 C++ 并且花了几个小时试图找出一种方法来将一个字节存储在某个内存地址,在我的情况下,所有(几乎所有)内存地址都不是动态的 - 所以地址指向,对于示例变量不会改变。

所以我试图检索存储在已知内存地址的单个字节。例如,让我们说:0x20000

例如,我试图检索的字节是0xEF.

现在我将如何在不使用取消引用运算符的情况下检索字节?所以基本上我需要在0xEF不必声明它是什么类型的数据类型的情况下获取,就像字面上只是物理获取字节一样0xEF。希望这是有道理的,我是个菜鸟:/

c++ memory byte memory-address

4
推荐指数
2
解决办法
3856
查看次数

拿wchar_t并放入char?

我已经尝试了一些东西,但还没有弄清楚如何获得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)

c++

1
推荐指数
1
解决办法
185
查看次数

标签 统计

c# ×2

c++ ×2

byte ×1

console-application ×1

memory ×1

memory-address ×1