System.Net.Http.Headers.AuthenticationHeaderValue.GetHashCode C# (CSharp) Method

GetHashCode() public method

public GetHashCode ( ) : int
return int
        public override int GetHashCode()
        {
            int result = StringComparer.OrdinalIgnoreCase.GetHashCode(_scheme);

            if (!string.IsNullOrEmpty(_parameter))
            {
                result = result ^ _parameter.GetHashCode();
            }

            return result;
        }

Usage Example

        public void GetHashCode_UseSameAndDifferentAuth_SameOrDifferentHashCodes()
        {
            AuthenticationHeaderValue auth1 = new AuthenticationHeaderValue("A", "b");
            AuthenticationHeaderValue auth2 = new AuthenticationHeaderValue("a", "b");
            AuthenticationHeaderValue auth3 = new AuthenticationHeaderValue("A", "B");
            AuthenticationHeaderValue auth4 = new AuthenticationHeaderValue("A");
            AuthenticationHeaderValue auth5 = new AuthenticationHeaderValue("A", "");
            AuthenticationHeaderValue auth6 = new AuthenticationHeaderValue("X", "b");

            Assert.Equal(auth1.GetHashCode(), auth2.GetHashCode());
            Assert.NotEqual(auth1.GetHashCode(), auth3.GetHashCode());
            Assert.NotEqual(auth1.GetHashCode(), auth4.GetHashCode());
            Assert.Equal(auth4.GetHashCode(), auth5.GetHashCode());
            Assert.NotEqual(auth1.GetHashCode(), auth6.GetHashCode());
        }