I'm capturing keys on my WinForm but I'm trying to see if the pressed key is a 'String' - getting an

Posted by Sergio Tapia on Stack Overflow See other posts from Stack Overflow or by Sergio Tapia
Published on 2010-04-28T02:36:28Z Indexed on 2010/04/28 2:43 UTC
Read the original article Hit count: 385

Filed under:
|
|

Here's my code:

        void gkh_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == neededLetter as Keys)
            {
                if (neededLetter == "n")
                {
                    neededLetter = "o";
                }
                else if (neededLetter == "o")
                {
                    neededLetter = "t";
                }
                else if (neededLetter == "t")
                {
                    neededLetter = "e";
                }
                else if (neededLetter == "e")
                {
                    this.Show();
                }
            }
            else
            { 
                neededLetter = "n";
            }
        }

I'm getting an error on the first If block:

The as operator must be used with a reference type or nullable type

© Stack Overflow or respective owner

Related posts about c#

Related posts about beginner