Enums vs dictionaries

  • Thread starter Thread starter hardieca
  • Start date Start date
H

hardieca

Hi,

I'm starting out with C#, and I'm wondering if someone could tell me
what is the difference between Enums and dictionaries... My book
doesn't even make reference to dictionaries, but while programming in
other languages, I used dictionaries quite often. Should I move to
Enums?

Thanks,

Chris
 
Pondering the eternal question of "Hobnobs or Rich Tea?",
(e-mail address removed) finally proclaimed:
what is the difference between Enums and dictionaries...

An enum is used to create a set of related constants, eg.

enum Temp {
BoilingPoint = 100,
MeltingPoint = 0,
}

System.Console.WriteLine("Boiling point is " + Temp.BoilingPoint);

Whereas dictionaries are used to create what is essentially an array of
objects that associates a key with a value, eg.

Dictionary<string, int> people = new Dictionary<string, int>();
people["Tom"] = 23;
people["Dick"] = 50;
people["Harry"] = 29;

System.Console.WriteLine("Dick is " + people["dick"] + " y.o");

The values within a dictionary can also be changed as and when you wish
to change them, and new key/value combinations can also be added at any
time. This is the opposite of enum, where they are essentially read only
once created.
 
Dylan Parry said:
Pondering the eternal question of "Hobnobs or Rich Tea?",
(e-mail address removed) finally proclaimed: ...

Ah - there are two famous quotes that have been misinterpreted over the
ages, that give the answer to the eternal question:

From an old friend of Shakespear's: "My kingdom, my kingom for a Hobnob"

And... (from a member of the French royalty, when they still tolerated
them): "Let them eat Rich Tea biscuits"

Chris
Use what talents you possess; the woods would be very silent if no birds
sang there except those that sang best. (William Blake)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top