Stack.Equals() Method in C#
Last Updated :
28 Jan, 2019
Equals(Object) Method which is inherited from the Object class is used to check if a specified Stack class object is equal to another Stack class object or not. This method comes under the System.Collections
namespace.
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 the above-discussed method:
Example 1:
using System;
using System.Collections;
class GFG {
public static void Main()
{
Stack st1 = new Stack();
st1.Push(1);
st1.Push(2);
st1.Push(3);
st1.Push(4);
Console.WriteLine(st1.Equals(st1));
}
}
|
Example 2:
using System;
using System.Collections;
class GFG {
public static void Main()
{
Stack st1 = new Stack();
st1.Push( "C" );
st1.Push( "C++" );
st1.Push( "Java" );
st1.Push( "C#" );
Stack st2 = new Stack();
st2.Push( "HTML" );
st2.Push( "CSS" );
st2.Push( "PHP" );
st2.Push( "SQL" );
Console.WriteLine(st1.Equals(st2));
Stack st3 = new Stack();
st3 = st2;
Console.WriteLine(st3.Equals(st2));
}
}
|
Share your thoughts in the comments
Please Login to comment...