C# | Check if an array object is equal to another array object
An array is a group of like-typed variables that are referred to by a common name. And each data item is called an element of the array. Equals(Object) method which is inherited by Array class from object class is used to check whether an array is equal to another array 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#
using System;
namespace geeksforgeeks {
class GFG {
public static void Main()
{
int [, ] intarray = new int [, ] { { 1, 2 },
{ 3, 4 },
{ 5, 6 },
{ 7, 8 } };
Console.WriteLine(intarray.Equals(intarray));
}
}
}
|
Example 2:
C#
using System;
namespace geeksforgeeks {
class GFG {
public static void Main()
{
String[] arr1 = new String[4] { "Sun", "Mon", "Tue", "Thu" };
String[] arr2 = new String[4] { "Sun", "Mon", "Tue", "Thu" };
Console.WriteLine(arr1.Equals(arr2));
String[] arr3 = new String[4];
arr3 = arr1;
Console.WriteLine(arr2.Equals(arr3));
Console.WriteLine(arr1.Equals(arr3));
}
}
}
|
Note: If the current instance is a reference type, the Equals(Object) method checks for reference equality.
Last Updated :
06 Jan, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...