C# | Check if two SortedList objects are equal
Equals(Object) Method which is inherited from the Object class is used to check whether the specified SortedList object is equal to another SortedList 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, false.
Below programs illustrate the use of above-discussed method:
Example 1:
using System;
using System.Collections;
class Geeks {
public static void Main(String[] args)
{
SortedList fslist = new SortedList();
fslist.Add( "Maths " , 98);
fslist.Add( "English " , 99);
fslist.Add( "Physics " , 97);
fslist.Add( "Chemistry" , 96);
fslist.Add( "CSE " , 100);
Console.WriteLine(fslist.Equals(fslist));
}
}
|
Output:
True
Example 2:
using System;
using System.Collections;
class Geeks {
public static void Main(String[] args)
{
SortedList fslist = new SortedList();
fslist.Add( "Maths " , 98);
fslist.Add( "English " , 99);
fslist.Add( "Physics " , 97);
fslist.Add( "Chemistry" , 96);
fslist.Add( "CSE " , 100);
SortedList fslist2 = new SortedList();
fslist2.Add( "1" , "one" );
fslist2.Add( "2" , "two" );
fslist2.Add( "3" , "three" );
fslist2.Add( "4" , "four" );
fslist2.Add( "5" , "five" );
Console.WriteLine(fslist.Equals(fslist2));
SortedList fslist3 = new SortedList();
fslist3 = fslist2;
Console.WriteLine(fslist3.Equals(fslist2));
}
}
|
Output:
False
True
Note: If the current instance is a reference type, the Equals(Object) method checks for reference equality.
Last Updated :
17 Dec, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...