473,472 Members | 2,241 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Enums vs dictionaries

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

Mar 23 '06 #1
3 12580
Pondering the eternal question of "Hobnobs or Rich Tea?",
ha******@hotmail.com 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
http://electricfreedom.org -- Where the Music Progressively Rocks!
Mar 23 '06 #2
Many thx!

Chris

Mar 23 '06 #3
"Dylan Parry" <us****@dylanparry.com> wrote in message
news:<um***************@dylanparry.com>...
Pondering the eternal question of "Hobnobs or Rich Tea?",
ha******@hotmail.com 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)

Mar 24 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Till Plewe | last post by:
Is there a way to speed up killing python from within a python program? Sometimes shutting down takes more than 10 times as much time as the actual running of the program. The programs are...
13
by: SpaceCowboy | last post by:
I recently got into a discussion with a co-worker about using enums across a dll interface. He wanted to use chars instead, argueing that depending on compiler settings the size of an enum could...
2
by: Faisal | last post by:
Can anyone tell me if it is possible to enumerate through all the Enums within a class . I have a class with many Enums and would like to accees the Enums through an array/collection etc. I can't...
27
by: Mark A. Gibbs | last post by:
i have been toying with the idea of making my enums smarter - ie, more in line with the rest of the language. i haven't tested it yet, but what i came up with is a template like this: template...
4
by: Martin Pritchard | last post by:
Hi, I'm working on a project that historically contains around 40 enums. In the database various fields refer to the int values of these enums, but of course ref integrity is not enofrced and...
210
by: Christoph Zwerschke | last post by:
This is probably a FAQ, but I dare to ask it nevertheless since I haven't found a satisfying answer yet: Why isn't there an "ordered dictionary" class at least in the standard list? Time and again...
2
by: Simon Elliott | last post by:
I have some legacy C++ code which requires some enums to be 1 or 2 bytes in size. I'd ideally like to be able to specify that a few carefully selected enums are a particular size. By default,...
11
by: Marc Gravell | last post by:
This one stumped me while refactoring some code to use generics... Suppose I declare an enum MyEnum {...} Is there a good reason why MyEnum doesn't implement IEquatable<MyEnum> ? Of course,...
14
by: cnb | last post by:
Are dictionaries the same as hashtables?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.