using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _6._10对象的比较equals
{
class Program
{
public string name;
public int age;
public Program(string name, int age)
{
this.name = name;
this.age = age;
}
static void Main(string[] args)
{
Program person = new Program("张三",12);
Program person1 = new Program("张三", 12);
if (person == person1)
{
Console.WriteLine("对象相同");
}
else {
Console.WriteLine("对象不相同");
}
person = person1;
if (person == person1)
{
Console.WriteLine("对象相同");
}
else
{
Console.WriteLine("对象不相同");
}
int a = 10;
int b = 20;
if (a == b )
{
Console.WriteLine("==对象相同");
}
else
{
Console.WriteLine("==对象不相同");
}
if (a .Equals(b ))
{
Console.WriteLine($"equals{a}{b}值相同 ");
}
else
{
Console.WriteLine($"equals{a }{b }值不相同");
}
a = b;
if (a .Equals(b ))
{
Console.WriteLine($"equals{a }{b }值相同");
}
else
{
Console.WriteLine($"equals{ a }{ b } 值不相同");
}
if (a == b)
{
Console.WriteLine("==对象相同");
}
else
{
Console.WriteLine("==对象不相同");
}
Console.ReadLine();
}
}
}