How do you implement GetHashCode for structure with two string, when both strings are interchangeable

前端 未结 14 2003
余生分开走
余生分开走 2020-12-08 09:05

I have a structure in C#:

public struct UserInfo
{
   public string str1
   {
     get;
     set;
   }

   public string str2
   {
     get;
     set;
   }           


        
14条回答
  •  遥遥无期
    2020-12-08 09:50

    public override int GetHashCode()   
    {       
        unchecked      
        {           
            return(str1 != null ? str1.GetHashCode() : 0) ^ (str2 != null ? str2.GetHashCode() : 0);       
        }   
    }
    

提交回复
热议问题