gpt4 book ai didi

c# - 计算具有字符串属性的类的哈希码的最佳方法是什么?

转载 作者:太空狗 更新时间:2023-10-29 21:28:46 25 4
gpt4 key购买 nike

<分区>

我有一个带有字符串属性的类,我需要覆盖 GetHashCode() 方法。

class A
{
public string Prop1 { get; set; }
public string Prop2 { get; set; }
public string Prop3 { get; set; }
}

第一个想法是做这样的事情:

public override int GetHashCode()
{
return Prop1.GetHashCode() ^ Prop2.GetHashCode() ^ Prop3.GetHashCode();
}

第二个想法是:

public override int GetHashCode()
{
return String.Join(";", new[] {Prop1, Prop2, Prop3}).GetHashCode();
}

什么是最好的方法?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com