![]() |
VOOZH | about |
In C#, a Dictionary<TKey, TValue> is a collection of key-value pairs. When we work with dictionaries, we may need to check if two dictionaries are equal. This means they contain the exact same keys and values.
In this article, we are going to learn how to check dictionary equality both by reference and by value in C#.
Syntax:
public virtual bool Equals (object obj);
This method checks whether two dictionary variables point to the same object in memory.
Example 1: Checking Reference Equality
True
Example 2: Checking Reference Inequality
False
To compare if two dictionaries have the same key-value pairs, here, we will use LINQ methods like Except().
Example: Value-Based Dictionary Comparison
Are dictionaries equal by value? True
Important Points: