Equals(Object) Method which is inherited from the Object class is used to check if a specified List<T> object is equal to another List<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)
{
List< int > firstlist = new List< int >();
firstlist.Add(17);
firstlist.Add(19);
firstlist.Add(21);
firstlist.Add(9);
firstlist.Add(75);
firstlist.Add(19);
firstlist.Add(73);
Console.WriteLine(firstlist.Equals(firstlist));
}
}
|
Example 2:
using System;
using System.Collections.Generic;
class Geeks {
public static void Main(String[] args)
{
List< string > list1 = new List< string >();
list1.Add( "DS" );
list1.Add( "C++" );
list1.Add( "Java" );
list1.Add( "JavaScript" );
List< int > list2 = new List< int >();
list2.Add(78);
list2.Add(44);
list2.Add(27);
list2.Add(98);
list2.Add(74);
Console.WriteLine(list1.Equals(list2));
List< int > list3 = new List< int >();
list3 = list2;
Console.WriteLine(list3.Equals(list2));
}
}
|
Note: If the current instance is a reference type, the Equals(Object) method checks for reference equality.
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 :
27 Jan, 2019
Like Article
Save Article