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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:15:03+00:00 2026-05-24T16:15:03+00:00

Animals is a dictionary class that contains Animal class objects. DictionaryBase implements IDictionaryEnumerator.GetEnumerator() and

  • 0

Animals is a dictionary class that contains Animal class objects. DictionaryBase implements IDictionaryEnumerator.GetEnumerator() and I have a problem with the way it displays the entries.

In the following code, I assumed it would display the entries in the same order they are added, however, it turns out they are displayed quite differently.

    Animals myAnimals = new Animals();
    myAnimals.Add("Swordy", new Animal("Swordy"));
    myAnimals.Add("Kollie", new Animal("Kollie"));
    myAnimals.Add("Charlie", new Animal("Charlie"));
    myAnimals.Add("Kilo", new Animal("Kilo"));
    myAnimals.Add("Alpha", new Animal("Alpha"));

    // Showing all of the entries with a foreach loop
    foreach (DictionaryEntry myEntry in myAnimals)
    {
        Console.WriteLine("Entry named {0}.", ((Animal)myEntry.Value).Name);
    }

This code resulted in this output(witch seems random to me):

Entry named Charlie.
Entry named Alpha.
Entry named Swordy.
Entry named Kollie.
Entry named Kilo.

How are the entries sorted? Is there a way to change it?

  • 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-24T16:15:04+00:00Added an answer on May 24, 2026 at 4:15 pm

    Dictionary uses hash table to store the objects, so the default sorting is based on GetHashCode method of each key that you insert into the dictionary.
    You can sort the dictionary by using LINQ for ex:

    myAnimals.OrderBy(e => ((Animal)e.Value).Name)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a table animals that has a column parent_id Say also that
I have a base class class Animal with pure virtual functions, and a set
I have a dictionary of objects, all of different types but derived from the
I have an object that has a list of abstract 'aninamls'. i.e. var animals
Suppose I have a dataset: data animals; input animal $ group $ control $;
Let's say I have a screen that shows the animals in my farm. If
I have the following xml that I need to deserialise to an object: <animals>
Say I have models: class Animal(models.Model): type = models.CharField(max_length=255) class Dog(Animal): def make_sound(self): print
Let us say I have a table called animals that looks like this: 1
I have a session variable $_SESSION[animals] containing a deep json object with values: $_SESSION[animals]='{

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.