
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Dictionary Methods in C#
Dictionary is a collection of keys and values in C#. Dictionary<TKey, TValue> is included in the System.Collection.Generics namespace.
The following are the methods −
Sr.No | Method & Description |
---|---|
1 | Add Add key-value pairs in Dictionary |
2 | Clear() Remove all keys and values |
3 | Remove Removes the element with the specified key. |
4 | ContainsKey Checks whether the specified key exists in Dictionary<TKey, TValue>. |
5 | ContainsValue Checks whether the specified key value exists in Dictionary<TKey, TValue>. |
6 | Count Count the number of key-value pairs. |
7 | Clear Removes all the elements from Dictionary<TKey, TValue>. |
Let us see how to add elements into a Dictionary and display the count.
Example
using System; using System.Collections.Generic; public class Demo { public static void Main() { IDictionary<int, int> d = new Dictionary<int, int>(); 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
- Related Questions & Answers
- Dictionary Methods in Python
- Dictionary Methods in Java
- Dictionary Methods in Python Program
- Dictionary Methods in Python (update(), has_key(), fromkeys()
- Built-in Dictionary Functions & Methods in Python
- Dictionary Methods in Python (cmp(), len(), items()…)
- Dictionary Class in C#
- Alien Dictionary in C++
- Anonymous Methods in C#
- Private Methods in C#
- Path methods in C#
- TimeSpan.From methods in C# ()
- Extension Methods in C#
- Hashtable vs. Dictionary in C#
- Case-insensitive Dictionary in C#
Advertisements