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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:30:33+00:00 2026-06-16T03:30:33+00:00

I have the following declaration: Dictionary<string, Dictionary<string, string>> like = new Dictionary<string, Dictionary<string, string>>();

  • 0

I have the following declaration:

Dictionary<string, Dictionary<string, string>> like = new Dictionary<string, Dictionary<string, string>>();

I need to get the first element out, but do not know the key or value. What’s the best way to do this?

  • 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-16T03:30:34+00:00Added an answer on June 16, 2026 at 3:30 am

    Note that to call First here is actually to call a Linq extension of IEnumerable, which is implemented by Dictionary<TKey,TValue>. But for a Dictionary, “first” doesn’t have a defined meaning. According to this answer, the last item added ends up being the “First” (in other words, it behaves like a Stack), but that is implementation specific, it’s not the guaranteed behavior. In other words, to assume you’re going to get any defined item by calling First would be to beg for trouble — using it should be treated as akin to getting a random item from the Dictionary, as noted by Bobson below. However, sometimes this is useful, as you just need any item from the Dictionary.


    Just use the Linq First():

    var first = like.First();
    string key = first.Key;
    Dictionary<string,string> val = first.Value;
    

    Note that using First on a dictionary gives you a KeyValuePair, in this case KeyValuePair<string, Dictionary<string,string>>.


    Note also that you could derive a specific meaning from the use of First by combining it with the Linq OrderBy:

    var first = like.OrderBy(kvp => kvp.Key).First();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following decleration: private Dictionary<string, Dictionary<string, File>> listFiles = new Dictionary<string,Dictionary<string,File>>(); How
If I have the following declaration: Map<String, Map<String, Person>> families = Collections.synchronizedMap(new HashMap<String, Map<String,
i have the following property declaration Public Property IsAreaSelected() As Integer Get Return If(ViewState(IsAreaSelected)
I have the following method declaration: public static bool SerializeObject<T>(string filename, T objectToSerialize){ I
I have the following declaration: public static readonly DependencyProperty PassColorProperty = DependencyProperty.RegisterAttached(PassColor, typeof(string), typeof(ColorMasking),
I have a following method declaration in VB and need to translate it into
In my class, I want to use a dictionary with the following declaration: Dictionary<string,
I have following LinkedHashMap declaration. LinkedHashMap<String, ArrayList<String>> test1 my point is how can i
I have the following declaration in a function in VBA: Set dict = CreateObject(Scripting.Dictionary)
I have the following declaration in .NET. I want to know what exactly this

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.