![]() |
IDictionary Interface is an interface that belongs to the collection module where we can access the elements by keys. Or we can say that the IDictionary interface is a collection of key/value pairs. It is available for both generic and non-generic types collection. Here each pair must contain a unique key and the value does not have to be null or can be null. The key/value pairs of non-generic IDictionary Interface are stored in a DictionaryEntry object and the key/value pairs of generic IDictionary Interface are stored in KeyValuePain<TKey, TValue> object. Syntax: public interface IDictionary : ICollection, IEnumerable Or we can use the IDictionary interface by using the following syntax. void Interface_name(IDictionary<key_datatype, value_datatype> object) { // Methods............ // Statements......... } where key_datatype represents the key datatype and value_datatype represents the value datatype Property Let us discuss the common properties of the IDictionary Interface:
Method Let us discuss the common methods of the IDictionary Interface:
In this article, we are going to create a dictionary and display the data using the IDictionary interface. Approach 1. Create a dictionary with key and values as string type to store the data of students. Dictionary<string, string> Student = new Dictionary<string, string>(); 2. Add values to dictionary. Student["Subject"] = "php"; Student["Subject"] = "java"; 3. Create a method with IDictionary interface to display the data present in the dictionary. static void Display(IDictionary<string, string> i) { Console.WriteLine(i["Subject"]); } 4. Call this method in the main method. Display(Student); Example: C#
Output: php java |
Reffered: https://www.geeksforgeeks.org
C# |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |