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

  • Home
  • SEARCH
  • 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 8002237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:17:51+00:00 2026-06-04T16:17:51+00:00

Half the time I need to find a value based on string, their name,

  • 0

Half the time I need to find a value based on string, their name, and the other half I need to find a value based on an int, their user ID.

Currently I have two dictionaries to solve this dilemma – one that uses a string as a key and one that uses an int as a key. I was wondering if there is a more efficient way to do this – a way to get a value based on int or string.

    public static Dictionary<int, Player> nPlayers = new Dictionary<int, Player>();
    public static Dictionary<string, Player> sPlayers = new Dictionary<string, Player>();

After scanning the other questions, someone mentioned using a dictionary of dictionaries. If anyone can elaborate on this (if it’s the solution I’m looking for), that’d be grand

I don’t know much about a tuple, but from what I understand it requires two keys, and what I am looking for takes one or the other.

Would Dictionary<object, Player> do the trick? I have no idea.

Please help me in my narrow-minded coding experience. ;_;

  • 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-06-04T16:17:53+00:00Added an answer on June 4, 2026 at 4:17 pm

    As per your comment when user logged in to system you adding them to a dictionary, here you have to add to both dictionaries.

    I think you can do this in another way,

       public static List<Player> nPlayers = new List<Player>();
    

    That’s only you need, add players when they logged in.

    If you want to search by ID, Name or whatever you can query nPlayers and find the Player.

     var playerByID = nPlayers.Where(p= p.ID==givenID).FirstOrDefault();
    
     var playerByName = nPlayers.Where(p= p.Name==givenName).FirstOrDefault();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have time stamps as string format Sun Jul 10 17:47:55 EDT 2011 I
I display favicon's from other sites on my page. About half the time they
I've wasted at least a half day of my company's time searching the Internet
I have spent about half a day searching for an answer to this question
We have about half a million images residing in the file system. Multiple images
I have an object that contains about half a dozen properties. I expect to
here's my dilema. I have for example this string: 1 2 3 4 5
I have a php script that returns an echo of 'Hello' when accessed half
I need to make a DirectX 3D mesh at run time using Managed DirectX
Currently my jsp 2.0 tags that need spring beans use this code: ac =

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.