Equals(Object) Method which is inherited from the Object class is used to check if a specified HashSet<T> object is equal to another HashSet<T> 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:
using System;
using System.Collections.Generic;
class Geeks {
public static void Main(String[] args)
{
HashSet< string > mySet = new HashSet< string >();
mySet.Add( "DS" );
mySet.Add( "C++" );
mySet.Add( "Java" );
mySet.Add( "JavaScript" );
Console.WriteLine(mySet.Equals(mySet));
}
}
|
Example 2:
using System;
using System.Collections.Generic;
class Geeks {
public static void Main(String[] args)
{
HashSet< string > mySet1 = new HashSet< string >();
mySet1.Add( "HTML" );
mySet1.Add( "CSS" );
mySet1.Add( "PHP" );
mySet1.Add( "DBMS" );
HashSet< int > mySet2 = new HashSet< int >();
for ( int i = 0; i < 5; i++) {
mySet2.Add(i * 2);
}
Console.WriteLine(mySet1.Equals(mySet2));
HashSet< int > mySet3 = new HashSet< int >();
mySet3 = mySet2;
Console.WriteLine(mySet3.Equals(mySet2));
}
}
|
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
01 Feb, 2019
Like Article
Save Article