此方法用于比较两个整数对象,并返回布尔值true或false。
语法:
bool int.equals(int objA, int objB);
Parameter(s):
int objA,int objB –用于表示两个要比较的整数对象。
返回值:
bool-如果两个对象相等,则返回“ true”,否则返回“ false”。
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");
}
}
}
}输出结果
Enter A: 10 Enter B: 15 Both are not equal Enter A: 10 Enter B: 10 Both are equal