本文整理汇总了C#中PathString.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# PathString.GetHashCode方法的具体用法?C# PathString.GetHashCode怎么用?C# PathString.GetHashCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PathString
的用法示例。
在下文中一共展示了PathString.GetHashCode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EqualityIsImplementedAndOrdinalIgnoreCaseByDefault
public void EqualityIsImplementedAndOrdinalIgnoreCaseByDefault(string value1, string value2, bool equal)
{
var path1 = new PathString(value1);
var path2 = new PathString(value2);
var object1 = (object)path1;
var object2 = (object)path2;
var object1B = object1;
// value equality
(path1 == path2).ShouldBe(equal);
(path1 != path2).ShouldBe(!equal);
(path1.Equals(path2)).ShouldBe(equal);
(Equals(path1, path2)).ShouldBe(equal);
// reference equality
ReferenceEquals(object1, object2).ShouldBe(false);
ReferenceEquals(object1, object1B).ShouldBe(true);
(object1 == object2).ShouldBe(false);
(object1 != object2).ShouldBe(true);
(object1 == object1B).ShouldBe(true);
(object1 != object1B).ShouldBe(false);
// object equality
(object1.Equals(object2)).ShouldBe(equal);
(Equals(object1, object2)).ShouldBe(equal);
// Compile error: (path1 == object2).ShouldBe(equal);
// Compile error: (path1 != object2).ShouldBe(!equal);
(path1.Equals(object2)).ShouldBe(equal);
(Equals(path1, object2)).ShouldBe(equal);
// Compile error: (object1 == path2).ShouldBe(equal);
// Compile error: (object1 != path2).ShouldBe(!equal);
(object1.Equals(path2)).ShouldBe(equal);
(Equals(object1, path2)).ShouldBe(equal);
// hash code equality
(path1.GetHashCode() == path2.GetHashCode()).ShouldBe(equal);
(object1.GetHashCode() == object2.GetHashCode()).ShouldBe(equal);
(object1.GetHashCode() == object2.GetHashCode()).ShouldBe(equal);
(path1.GetHashCode() == object2.GetHashCode()).ShouldBe(equal);
// dictionary equality
var dictionaryPathString = new Dictionary<PathString, object>();
dictionaryPathString[path1] = "first";
dictionaryPathString[path2] = "second";
(dictionaryPathString.Count == 1).ShouldBe(equal);
var dictionaryObject = new Dictionary<object, object>();
dictionaryObject[path1] = "first";
dictionaryObject[path2] = "second";
(dictionaryObject.Count == 1).ShouldBe(equal);
}