当前位置: 首页>>代码示例>>C#>>正文


C# CancellationToken.GetHashCode方法代码示例

本文整理汇总了C#中System.Threading.CancellationToken.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# CancellationToken.GetHashCode方法的具体用法?C# CancellationToken.GetHashCode怎么用?C# CancellationToken.GetHashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Threading.CancellationToken的用法示例。


在下文中一共展示了CancellationToken.GetHashCode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CancellationToken_GetHashCode

        public static void CancellationToken_GetHashCode()
        {
            CancellationTokenSource cts = new CancellationTokenSource();
            CancellationToken ct = cts.Token;
            int hash1 = cts.GetHashCode();
            int hash2 = cts.Token.GetHashCode();
            int hash3 = ct.GetHashCode();

            Assert.Equal(hash1, hash2);
            Assert.Equal(hash2, hash3);

            CancellationToken defaultUnsetToken1 = new CancellationToken();
            CancellationToken defaultUnsetToken2 = new CancellationToken();
            int hashDefaultUnset1 = defaultUnsetToken1.GetHashCode();
            int hashDefaultUnset2 = defaultUnsetToken2.GetHashCode();
            Assert.Equal(hashDefaultUnset1, hashDefaultUnset2);

            CancellationToken defaultSetToken1 = new CancellationToken(true);
            CancellationToken defaultSetToken2 = new CancellationToken(true);
            int hashDefaultSet1 = defaultSetToken1.GetHashCode();
            int hashDefaultSet2 = defaultSetToken2.GetHashCode();
            Assert.Equal(hashDefaultSet1, hashDefaultSet2);

            Assert.NotEqual(hash1, hashDefaultUnset1);
            Assert.NotEqual(hash1, hashDefaultSet1);
            Assert.NotEqual(hashDefaultUnset1, hashDefaultSet1);
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:27,代码来源:CancellationTokenTests.cs

示例2: CancellationToken_GetHashCode

        private static bool CancellationToken_GetHashCode()
        {
            TestHarness.TestLog("* CancellationTokenTests.CancellationToken_GetHashCode()");
            bool passed = true;

            CancellationTokenSource cts = new CancellationTokenSource();
            CancellationToken ct = cts.Token;
            int hash1 = cts.GetHashCode();
            int hash2 = cts.Token.GetHashCode();
            int hash3 = ct.GetHashCode();

            passed &= TestHarnessAssert.AreEqual(hash1, hash2, "[1]Hashes should be equal.");
            passed &= TestHarnessAssert.AreEqual(hash2, hash3, "[2]Hashes should be equal.");


            CancellationToken defaultUnsetToken1 = new CancellationToken();
            CancellationToken defaultUnsetToken2 = new CancellationToken();
            int hashDefaultUnset1 = defaultUnsetToken1.GetHashCode();
            int hashDefaultUnset2 = defaultUnsetToken2.GetHashCode();
            passed &= TestHarnessAssert.AreEqual(hashDefaultUnset1, hashDefaultUnset2, "[3]Hashes should be equal.");


            CancellationToken defaultSetToken1 = new CancellationToken(true);
            CancellationToken defaultSetToken2 = new CancellationToken(true);
            int hashDefaultSet1 = defaultSetToken1.GetHashCode();
            int hashDefaultSet2 = defaultSetToken2.GetHashCode();
            passed &= TestHarnessAssert.AreEqual(hashDefaultSet1, hashDefaultSet2, "[4]Hashes should be equal.");



            passed &= TestHarnessAssert.AreNotEqual(hash1, hashDefaultUnset1, "[5]Hashes should be different.");
            passed &= TestHarnessAssert.AreNotEqual(hash1, hashDefaultSet1, "[6]Hashes should be different.");
            passed &= TestHarnessAssert.AreNotEqual(hashDefaultUnset1, hashDefaultSet1, "[7]Hashes should be different.");


            return passed;
        }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:37,代码来源:CancellationTokenTests.cs


注:本文中的System.Threading.CancellationToken.GetHashCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。