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 7999045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:23:14+00:00 2026-06-04T15:23:14+00:00

I want to use a 2-D array in C#, e.g: string[,] a = new

  • 0

I want to use a 2-D array in C#, e.g:

string[,] a = new string[,]
{
    {"aunt", "AUNT_ID"},
    {"Sam", "AUNT_NAME"},
    {"clozapine", "OPTION"},
};

My requirement is that when I pass "aunt" to this array I want to get corresponding AUNT_ID from the 2-D array.

  • 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-04T15:23:16+00:00Added an answer on June 4, 2026 at 3:23 pm

    As others have said, a Dictionary<string, string> would be better – and you can use a collection initializer to create it simply:

    Dictionary<string, string> dictionary = new Dictionary<string, string>
    {
        {"ant", "AUNT_ID"},
        {"Sam", "AUNT_NAME"},
        {"clozapine", "OPTION"},
    };
    

    If you’re confident that your key is in the dictionary, and you’re happy for an exception to be thrown otherwise:

    string value = dictionary[key];
    

    or if it might not be:

    string value;
    if (dictionary.TryGetValue(key, out value))
    {
        // Use value here
    }
    else
    {
        // Key wasn't in dictionary
    }
    

    If you really need to use an array, if you can change it to a multidimensional array (string[][]), you can use:

    // Will throw if there are no matches
    var value = array.First(x => x[0] == key)[1];
    

    Or again to be more circumspect:

    var pair = array.FirstOrDefault(x => x[0] == key);
    if (pair != null)
    {
        string value = pair[1];
        // Use value here
    }
    else
    {
        // Key wasn't in dictionary
    }
    

    LINQ unfortunately doesn’t work quite as well on rectangular arrays. It probably wouldn’t be too hard to write a method to allow it to be treated “somewhat” like an array of arrays, admittedly…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello i do want a sort an array, that contains this: String[] info =
I want to use an array of string the same as this: char arr[][20]
I have an array of strings plus one additional string. I want to use
I have an array of strings that I want to use for button titles
I want to take an array and use that array's values to populate an
I have this as a string 02/06/2012 1:25 PM EST I want to use
so I want to use this JQuery plugin that Stack Overflow has made available
I have an array of type string which I want to re-use inside a
I have a string array like this: string[] names = new string[] { john,
I want to use that array of characters in my game of hangman to

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.