Home » C#.Net

Int32.Equals() method with example in C#

C# Int32.Equals() method: Here, we are going to learn about the Equals() method of int (Int32) struct with its description, syntax, and example.
Submitted by IncludeHelp, on October 02, 2019

Int32.Equals() Method

This method is used to compare two integer objects and returns boolean values either true or false.

Syntax:

    bool int.equals(int objA, int objB);

Parameter(s):

  • int objA, int objB – are used to represent two integer objects to be compared.

Return value:

bool – it returns "true" if both objects are equal, else it returns "false".

Int32.Equals() Method Example in C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 0;
            int b = 0;

            Console.Write("Enter A: ");
            a = Convert.ToInt32(Console.ReadLine());

            Console.Write("Enter B: ");
            b = Convert.ToInt32(Console.ReadLine());

            if (int.Equals(a, b) == true)
            {
                Console.WriteLine("Both are equal");
            }
            else
            {
                Console.WriteLine("Both are not equal");
            }
        }
    }
}

Output

Enter A: 10
Enter B: 15
Both are not equal

Enter A: 10
Enter B: 10
Both are equal



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.