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


C# CultureInfo.GetHashCode方法代码示例

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


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

示例1: PosTest1

    // Returns true if the expected result is right
    // Returns false if the expected result is wrong
    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: CultureTypes.SpecificCultures");
        try
        {

            CultureInfo myCultureInfo = new CultureInfo("en-US");
            // the only guarantee that can be made about HashCodes is that they will be non-zero 
            //  and unique across calls
            int actualValue   = myCultureInfo.GetHashCode();
            int expectedValue = myCultureInfo.GetHashCode();
            if (actualValue != expectedValue)
            {
                TestLibrary.TestFramework.LogError("001", "myCultureInfo.GetHashCode() " + actualValue + "  should return " + expectedValue);
                retVal = false;
            }
            if (0 == actualValue)
            {
                TestLibrary.TestFramework.LogError("101", "myCultureInfo.GetHashCode() " + actualValue + "  should not return 0");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
            retVal = false;
        }
        return retVal;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:33,代码来源:cultureinfogethashcode.cs

示例2: Compare

        public static void Compare(string x, string y, string cultureName, CompareOptions options, int expectedWindows, int expectedICU)
        {
            int expected = s_isWindows ? expectedWindows : expectedICU;
            StringComparer comparer = new CultureInfo(cultureName).CompareInfo.GetStringComparer(options);

            Assert.Equal(expected, Math.Sign(comparer.Compare(x, y)));
            Assert.Equal((expected == 0), comparer.Equals(x, y));

            if (x != null && y != null)
            {
                Assert.Equal((expected == 0), comparer.GetHashCode(x).Equals(comparer.GetHashCode(y)));
            }
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:13,代码来源:GetStringComparerTests.cs

示例3: PosTest2

    public bool PosTest2()
    {
        bool retVal = true;
        const string c_TEST_DESC = "PosTest2: Verify the TextInfo is not same  CultureInfo's . ";
        const string c_TEST_ID = "P002";


        TextInfo textInfoFrance = new CultureInfo("fr-FR").TextInfo;
        TextInfo textInfoUS = new CultureInfo("en-US").TextInfo;

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            int franceHashCode = textInfoFrance.GetHashCode();
            int usHashCode = textInfoUS.GetHashCode();
            if (franceHashCode == usHashCode)
            {
                string errorDesc = "the differente TextInfo's HashCode should not equal. ";
                TestLibrary.TestFramework.LogError("003" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }

        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004" + " TestId-" + c_TEST_ID, "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:32,代码来源:textinfogethashcode.cs

示例4: Equals

        public void Equals(string cultureName1, CompareOptions options1, string cultureName2, CompareOptions options2, bool expected)
        {
            StringComparer comparer1 = new CultureInfo(cultureName1).CompareInfo.GetStringComparer(options1);
            StringComparer comparer2 = new CultureInfo(cultureName2).CompareInfo.GetStringComparer(options2);

            Assert.Equal(expected, comparer1.Equals(comparer2));
            Assert.Equal(expected, comparer1.GetHashCode().Equals(comparer2.GetHashCode()));
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:8,代码来源:GetStringComparerTests.cs

示例5: CompareInfoIdentityTests

        public static void CompareInfoIdentityTests()
        {
            StringComparer us = new CultureInfo("en-US").CompareInfo.GetStringComparer(CompareOptions.IgnoreCase);
            StringComparer us2 = new CultureInfo("en-US").CompareInfo.GetStringComparer(CompareOptions.IgnoreCase);
            StringComparer usNoSym = new CultureInfo("en-US").CompareInfo.GetStringComparer(CompareOptions.IgnoreSymbols);
            StringComparer fr = new CultureInfo("fr-FR").CompareInfo.GetStringComparer(CompareOptions.IgnoreCase);
            StringComparer frOrdinal = new CultureInfo("fr-FR").CompareInfo.GetStringComparer(CompareOptions.Ordinal);

            Assert.True(us.Equals(us2));
            Assert.False(us.Equals(usNoSym));
            Assert.False(us.Equals(fr));
            Assert.False(us.Equals(frOrdinal));

            Assert.Equal(us.GetHashCode(), us2.GetHashCode());
            Assert.NotEqual(us.GetHashCode(), usNoSym.GetHashCode());
            Assert.NotEqual(us.GetHashCode(), fr.GetHashCode());
            Assert.NotEqual(frOrdinal.GetHashCode(), fr.GetHashCode());
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:18,代码来源:GlobalizationExtensionsTests.cs

示例6: CompareInfoBasicTests

        public static void CompareInfoBasicTests()
        {
            string one = "A test string";
            string aCopyOfOne = one;

            StringComparer comp = new CultureInfo("fr-FR").CompareInfo.GetStringComparer(CompareOptions.IgnoreCase);

            Assert.Equal(0, comp.Compare(one, aCopyOfOne));
            Assert.True(comp.Equals(one, aCopyOfOne));

            Assert.Equal(-1, comp.Compare(null, one));
            Assert.Equal(0, comp.Compare(null, null));
            Assert.Equal(1, comp.Compare(one, null));

            Assert.False(comp.Equals(null, one));
            Assert.True(comp.Equals(null, null));
            Assert.False(comp.Equals(one, null));

            Assert.Equal(comp.GetHashCode("abc"), comp.GetHashCode("ABC"));
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:20,代码来源:GlobalizationExtensionsTests.cs

示例7: GetHashCode

 public void GetHashCode(string name)
 {
     // The only guarantee that can be made about HashCodes is that they will be the same across calls
     CultureInfo culture = new CultureInfo(name);
     Assert.Equal(culture.GetHashCode(), culture.GetHashCode());
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:6,代码来源:CultureInfoGetHashCode.cs


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