Last post Mar 05, 2020 06:37 AM by EvanChatter
Nov 11, 2017 05:26 AM|Khan_1|LINK
I made a method for fetching data as Dicitonary, I thought that dic vs Idic has not much difference, but when I compiled the project it was building successfully, because I am using Dictionary but in returning from method ,I was returning Idictionary.
as i change the Idictionary to dictionary then it built successfully.
I am confused little bit , because both has same declaration.
b) I need some practice material to get value of dictionary which has class. the best way
Nov 14, 2017 06:19 AM|Rohit Rao|LINK
IDictionary is an interface. We can think it as a Contract that provides information (Properties / Methods) of what an implementing class will do.
Dictionary is a Class or we can say the Concrete class that implements IDcitionary interface, So you will get all the method (Contract) of IDictionary implemented in Dictionary class. The following code will always work as Dictionary class Implements IDictionary
static void Main(string args)
IDictionary<int, string> Result = TestMethod();
foreach (string name in Result.Values)
public static IDictionary<int, string> TestMethod()
Dictionary<int, string> Name = new Dictionary<int, string>();
Let me know if you need more details.
Nov 14, 2017 08:16 AM|Cathy Zou|LINK
IDictionary is only an interface - a contract which describes what an implementing class must do. Dictionary is a concrete class that implements that interface and hence must provide the methods described in the IDictionary interface.
If you want to create a dictionary you must create a concrete class (i.e. Dictionary), but if all you want to do with that dictionary is methods exposed by the IDictionary interface you can pass the concreate class round as an interface - which reduces the
coupling between methods.
For more description about this, you could refer to following links:
Mar 05, 2020 06:37 AM|EvanChatter|LINK
The difference is that Dictionary is concrete implementation while IDictionary is just a contract, abstraction. If IDictionary is a "more generic" type than
Dictionary then it makes sense to use the more generic type in declaring variables. It is a good idea to abstract yourself from an implementation, by that I mean programming against
an interface rather than a concrete implementation