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


C# SortedList.SetByIndex方法代码示例

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


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

示例1: runTest


//.........这里部分代码省略.........
             strLoc = "Loc_63rfdg";
             try
             {
                 iCountTestcases++;
                 slst1[null] = "Not a chance";
                 iCountErrors++;
                 Console.WriteLine("Err_7439dg! Exception not thrown");
             }
             catch(ArgumentNullException)
             {
             }
             catch(Exception ex)
             {
                 iCountErrors++;
                 Console.WriteLine("Err_7653dsv! Unexpected exception thrown, " + ex);
             }
             strValue = null;
             slst1[51] =  strValue ;
             if(slst1[51] != null) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_752dsg! Expected value not returned, " + slst1[51]);
             }
             strLoc = "Loc_7435gfdsg";
             iNumberOfElements = 10;
             slst1 = new SortedList();
             for(int i=iNumberOfElements-1; i>=0;i--)
             {
                 slst1.Add(50 + i, "Value_" + i);
             }
             for(int i=0; i<slst1.Count;i++)
             {
                 strValue = "Value_" + i + 50;
                 slst1.SetByIndex(i, strValue);
             }
             for(int i=0; i<slst1.Count;i++)
             {
                 strValue = "Value_" + i + 50;
                 if(!strValue.Equals(slst1.GetByIndex(i))) 
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_003oo! Expected value not returned, " + strValue + " " + slst1.GetByIndex(i));
                 }
             }
             strLoc = "Loc_7645cfxgd";
             try
             {
                 iCountTestcases++;
                 slst1.SetByIndex(-1, strValue);
                 iCountErrors++;
                 Console.WriteLine("Err_7439dg! Exception not thrown");
             }
             catch(ArgumentOutOfRangeException)
             {
             }
             catch(Exception ex)
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0155234sfdg! Unexpected exception thrown, " + ex);
             }
             try
             {
                 iCountTestcases++;
                 slst1.SetByIndex(slst1.Count, strValue);
                 iCountErrors++;
                 Console.WriteLine("Err_7439dg! Exception not thrown");
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:67,代码来源:co3953multimethods.cs

示例2: Test01


//.........这里部分代码省略.........
            //already existent ones
            strValue = "Value_1";
            Assert.Equal(strValue, slst1[51]);

            strValue = "Different value";
            slst1[51] = strValue;
            Assert.Equal(strValue, slst1[51]);

            //paramter stuff
            Assert.Throws<ArgumentNullException>(() =>
                             {
                                 slst1[null] = "Not a chance";
                             }
            );

            strValue = null;
            slst1[51] = strValue;
            Assert.Null(slst1[51]);

            //SetByIndex - this changes the value at this specific index. Note that SortedList
            //does not have the equicalent Key changing means as this is a SortedList and will be done
            //automatically!!!
            iNumberOfElements = 10;
            slst1 = new SortedList();

            for (int i = iNumberOfElements - 1; i >= 0; i--)
            {
                slst1.Add(50 + i, "Value_" + i);
            }

            for (int i = 0; i < slst1.Count; i++)
            {
                strValue = "Value_" + i + 50;
                slst1.SetByIndex(i, strValue);
            }

            for (int i = 0; i < slst1.Count; i++)
            {
                strValue = "Value_" + i + 50;
                Assert.Equal(strValue, slst1.GetByIndex(i));
            }
            //paramter stuff

            Assert.Throws<ArgumentOutOfRangeException>(() =>
                             {
                                 slst1.SetByIndex(-1, strValue);
                             }
            );

            Assert.Throws<ArgumentOutOfRangeException>(() =>
                             {
                                 slst1.SetByIndex(slst1.Count, strValue);
                             }
            );

            //CopyTo() - copies the values
            iNumberOfElements = 10;
            slst1 = new SortedList();

            for (int i = iNumberOfElements - 1; i >= 0; i--)
            {
                slst1.Add(50 + i, "Value_" + i);
            }

            ar1 = new DictionaryEntry[iNumberOfElements];
            slst1.CopyTo(ar1, 0);
开发者ID:er0dr1guez,项目名称:corefx,代码行数:67,代码来源:MultiMethodsTests.cs


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