using System;
// c#-运算符重载-等号运算符
namespace ConsoleApp10
{
class A {
public A(int b) => this.b = b;
public int b;
public static bool operator ==(A left, A right) {
return (left.b == right.b) ;
}
public static bool operator !=(A left, A right)
{
return !(left == right);
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
A a = new A(5);
A b = new A(5);
A c = new A(6);
Console.WriteLine(a == b);
Console.WriteLine(a == c);
}
}
}
c#-运算符重载-等号运算符
最新推荐文章于 2024-03-26 23:45:10 发布