

- 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
How to initialize a dictionary to an empty dictionary in C#?
To initialize a dictionary to an empty dictionary, use the Clear() method. It clears the dictionary and forms it as empty.
dict.Clear();
After that, use the Dictionary count property to check whether the list is empty or not −
if (dict.Count == 0) { Console.WriteLine("Dictionary is empty!"); }
Let us see the complete code −
Example
using System; using System.Collections.Generic; using System.Linq; namespace Demo { public class Program { public static void Main(string[] args) { var dict = new Dictionary < string, string > (); dict.Clear(); if (dict.Count == 0) { Console.WriteLine("Dictionary is empty!"); } } } }
Output
Dictionary is empty!
- Related Questions & Answers
- How to create an empty dictionary in Python?
- How to declare and initialize a dictionary in C#?
- How to define a Python dictionary within dictionary?
- How to initialize an empty DateTime in C#
- How to convert Javascript dictionary to Python dictionary?
- How to initialize a list to an empty list in C#?
- How to initialize a string to an empty string in C#?
- How to initialize a tuple to an empty tuple in C#?
- Python - Check if dictionary is empty
- How to initialize an empty array list in Kotlin?
- How to convert a String representation of a Dictionary to a dictionary in Python?
- Convert string dictionary to dictionary in Python
- How to convert the string representation of a dictionary to a dictionary in python?
- How to create a Dictionary in PowerShell?
- How to create a dictionary in Python?
Advertisements