我試圖倍率Equals方法在C#和我收到錯誤等倍率Equals方法在C#
SoftCherry.Customer」是‘類型’,但使用類似‘變量’
錯誤行:返回this.FirstName ==((客戶)的obj).FirstName & & this.LastName ==((客戶)的obj).LastName;在客戶類
,這是我的代碼
using System;
namespace SoftCherry
{
public class MainClass
{
public static void Main()
{
Customer C1 = new Customer();
C1.FirstName = "Raja";
C1.LastName = "Thananki";
Customer C2= new Customer();
C2.FirstName = "Raja";
C2.LastName = "Thananki";
Console.WriteLine(C1== C2);
Console.WriteLine(C1.Equals(C2));
Console.ReadLine();
}
}
public class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
if (!(obj is Customer))
{
return false;
}
return this.FirstName == ((Customer).obj).FirstName &&
this.LastName == ((Customer).obj).LastName;
}
public override int GetHashCode()
{
return this.FirstName.GetHashCode()^this.LastName.GetHashCode();
}
}
}
丟失'obj'前的小圓點。 – Jon