Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 630485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:51:36+00:00 2026-05-13T19:51:36+00:00

My question is pretty simple, but I didn’t find a way to implement my

  • 0

My question is pretty simple, but I didn’t find a way to implement my code the way I want it to be. So I started wondering if the code I want to implement is not good. And if it is, what’s the best way to do it.

Here it goes:

class InputManager  
{  
    SortedDictionary<ushort,Keys> inputList = new SortedDictionary<ushort,Keys>();  

    public void Add(ushort id, Keys key) {...}  
    public bool IsPressed(ushort id) {...}  
}  

class Main  
{  
    private enum RegisteredInput : ushort  
    {  
        Up,  
        Down,  
        Confirm  
    }  

    public Main()  
    {  
            InputManager manager = new InputManager();

            manager.Add(RegisteredInput.Up, Keys.Q);
            manager.Add(RegisteredInput.Down, Keys.A);
            manager.Add(RegisteredInput.Confirm, Keys.Enter);
    }

    void update()
    {
    if(manager.IsPressed(RegisteredInput.Up)) action();
    }
}

This code won’t compile, giving errors of this kind:

The best overloaded method match for ‘InputManager.Add(ushort, Keys)’ has some invalid arguments
Argument ‘1’: cannot convert from ‘RegisteredInput’ to ‘ushort’

If I use a cast like in manager.Add((ushort)RegisteredInput.Up, Keys.Q); it will work. But because the cast must be explicit, I was wondering if it is not recomended code in C# like it is in C++ and if there is a better way of doing it (like using const ushort for every value, which I kinda don’t like much).

The best answer I got so far was from this thread, but it sounds so much like a hack, I got worried.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:51:36+00:00Added an answer on May 13, 2026 at 7:51 pm

    Make InputManager a generic type. IE:

    class InputManager<T>
    {
       SortedDictionary<T,Keys> inputList = new SortedDictionary<T,Keys>();  
    
       public void add(T id, Keys key) {...}  
       public bool isPressed(T id) {...}    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Question is pretty self explanitory. I want to do a simple find and replace,
I've got a question that probably has a pretty simple answer, but I didn't
I'm pretty sure this is a simple question in regards to formatting but here's
Pretty simple question, I'm writing an XML document and i'm not sure how to
Pretty simple question: When i have a persistable object, it usually has a property
My question is pretty vague :o) - But here is an example : When
This seems like a pretty softball question, but I always have a hard time
My question is pretty straightforward: You are an executable file that outputs Access granted
This question is pretty much the same as this .Net question exept for java.
I think the question is pretty self explanatory. Anyone done this before? UPDATE :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.