Dictionary C# में Keys और Values का Collection है। Dictionary<TKey, TValue> System.Collection.Generics Namespace में शामिल है।
निम्न Methods हैं:
| Sr.No | Method & Description |
|---|---|
| 1 | Add Dictionary में Key-Value Pairs Add करता है |
| 2 | Clear() सभी Keys और Values Remove करता है |
| 3 | Remove Specified Key वाले Element को Remove करता है। |
| 4 | ContainsKey Check करता है कि Specified Key Dictionary<TKey, TValue> में Exist करती है या नहीं। |
| 5 | ContainsValue Check करता है कि Specified Key Value Dictionary<TKey, TValue> में Exist करती है या नहीं। |
| 6 | Count Key-Value Pairs की संख्या Count करता है। |
| 7 | Clear Dictionary<TKey, TValue> से सभी Elements Remove करता है। |
आइए देखते हैं कि Dictionary में Elements कैसे Add करें और Count Display करें।
Example
using System; using System.Collections.Generic; public class Demo { public static void Main() { IDictionary d = new Dictionary(); d.Add(1,97); d.Add(2,89); d.Add(3,77); d.Add(4,88); d.Add(5,78); d.Add(6,98); Console.WriteLine(d.Count); } } Output
6