Equals(Object) Method which is inherited from the Object class is used to check if a specified StringCollection object is equal to another StringCollection object or not.
Syntax:
public virtual bool Equals (object obj);
Here, obj is the object which is to be compared with the current object.
Return Value: This method return true if the specified object is equal to the current object otherwise it returns false.
Below programs illustrate the use of above-discussed method:
Example 1:
// C# code to check if two // StringCollections are equal or not using System; using System.Collections.Specialized; class GFG { // Driver code public static void Main() { // creating a StringCollection named myCol StringCollection myCol = new StringCollection(); // Adding elements in StringCollection myCol.Add("A"); myCol.Add("B"); myCol.Add("C"); myCol.Add("D"); myCol.Add("E"); // Checking whether myCol is // equal to itself or not Console.WriteLine(myCol.Equals(myCol)); } } |
True
Example 2:
// C# code to check if two // StringCollections are equal or not using System; using System.Collections.Specialized; class GFG { // Driver code public static void Main() { // creating a StringCollection named my1 StringCollection my1 = new StringCollection(); // Adding elements in StringCollection my1.Add("GFG"); my1.Add("Noida"); my1.Add("DS"); my1.Add("Geeks"); my1.Add("Classes"); // Creating a StringCollection named my2 StringCollection my2 = new StringCollection(); my2.Add("Australia"); my2.Add("Belgium"); my2.Add("Netherlands"); my2.Add("China"); my2.Add("Russia"); my2.Add("India"); // Checking whether my1 is // equal to my2 or not Console.WriteLine(my1.Equals(my2)); // Creating a new StringCollection StringCollection my3 = new StringCollection(); // Assigning my2 to my3 my3 = my2; // Checking whether my3 is // equal to my2 or not Console.WriteLine(my3.Equals(my2)); } } |
False True
Note: If the current instance is a reference type, the Equals(Object) method checks for reference equality.
Recommended Posts:
- C# | Check if the StringCollection is read-only
- C# | Check if StringCollection is synchronized (thread safe)
- C# | Check if the specified string is in the StringCollection
- C# | Get the number of strings in StringCollection
- C# | Index of first occurrence in StringCollection
- C# | Get or Set at specified index in StringCollection
- C# | Remove from the specified index of the StringCollection
- C# | Copy StringCollection at the specified index of array
- C# | Remove the first occurrence from the StringCollection
- C# | Remove all the strings from the StringCollection
- C# | Insert at the specified index in StringCollection
- C# | Add a string to the end of the StringCollection
- C# | Copy the elements of a string array to the end of the StringCollection
- C# | StringCollection Class
- C# | Get an enumerator that iterates through StringCollection
- C# | Gets or sets the element at the specified index in StringCollection
- How to get Synchronize access to the StringCollection in C#
- How to create a StringCollection in C#
- C# | Check if two SortedList objects are equal
- C# | Check if two ListDictionary objects are equal
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

