MSDN上的解釋:In string concatenation Operations, the C# compiler treats a null string the same as an empty string, but it does not convert the value of the original null string.stackoverflow上的相關問題雖然不是什么大坑,但還是值得mark一下,我本來是定義了幾個類,因為需要放BindingList里頭做數據源,定義的類重載了Equals方法和GetHashCode方法以方便查找,代碼大概是這樣的: public class Person { public string FirstName { get; set; } public string SecondName { get; set; } public int Age { get; set; } public override bool Equals(object obj) { if (base.Equals(obj)) return true; var d = obj as Person; if (d == null) return false; return FirstName == d.FirstName && SecondName == d.SecondName; } public override int GetHashCode() { return string.Concat(FirstName, SecondName).GetHashCode(); } } public class Book { public string Id { get; set; } public double PRice { get; set; } public override bool Equals(object obj) { if (base.Equals(obj)) return true; var d = obj as Book; if (d == null) return false; return Id == d.Id; } public override int GetHashCode() { return Id.GetHashCode(); } }
新聞熱點
疑難解答