difference between dictionaries ,hashtable,arraylist in c# .net?
2. i want to know about interface in c# .net? how do achieve multiple inheritance in c#...got some material in google..not getting clear idea..can anyone explain me with understanding example?

Recommended Answers

All 2 Replies

Have you bothered this time to read the helpfile ?? or is this the same as all your other posts?

OK, for the first question

The dictionaries are a sort of collections those
represent a collection of keys and values, each value corresponds to a unique key,

they could be used also in a generic context


Dictionary<int, string> oDictionary = new Dictionary<int, string>();
oDictionary.Add(1, "One");
oDictionary.Add(2, "Two");
oDictionary.Add(3, "Three");

It is best used when you want to find out objects using their identifiers

The Hash table is similar to the dictionary I mean a collection of value pair too but a key difference between the two concepts is that dictioanry is faster as it doesn't need boxing and unbixing operation

boxing means convert a type to an object
object oPerson = new Person();
unboxing is the inverse of boxing is to convert an object to a determined type
Person x = oPerson as Person;

An arrayList is totally different as it accepts only value without key

ArrayList olist = new ArrayList();

For the second question

Multiple inheritence is not allowed in C# exactly like Java and totaly opposit to C++

Now, Imagine this situation

A champanzee Has a mouth, 2 eye, 2 ear, 1 nose
An Antilop like girafe Has a mouth, 2 eye, 2 ear, 1 nose
A Person Has a mouth, 2 eye, 2 ear, 1 nose

A champanzee is type of Monkeys
A girafe is type of Antilops
A Person is type of Humain

but all together have something in common

A mouth, 2 eye, 2 ear, 1 nose

so I can use an interface to tie them together

Interface IEarthFeature
  2 eyes;
  2 ears;
  1 nose;

Imagine this situation
Now imagine creatures from another planets are comming to the earth then Tome lee jones and will Smith in Man in black have as mission to clean the earth from those rubbish whom have 3eyes or 5 eyes, no mouth, 3 nose and so forth

foreach( IEarthFeature creature in the Earth)

The others whom doesn't respect the earth criteria will be Garbage collected poor creatures!!!

I can use also this senario

   if(creature is Champanzee) { say it is an animal;}
   if(creature is Girafe) { say it is an animal;}
   if(creature is Person) {say it is a Human;}
      say not identified;
      SendItToHell(creature); // Poor creature!!!
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.