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


C# SortedList.CopyTo方法代码示例

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


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

示例1: DoICollectionTests

        private void DoICollectionTests(SortedList good, ICollection bad, Hashtable hsh1, DicType dic)
        {
            if (good.Count != bad.Count)
                hsh1["Count"] = "";

            if (good.IsSynchronized != bad.IsSynchronized)
                hsh1["IsSynchronized"] = "";

            if (good.SyncRoot != bad.SyncRoot)
                hsh1["SyncRoot"] = "";

            //CopyTo
            string[] iArr1 = null;
            string[] iArr2 = null;
            DictionaryEntry[] dicEnt1;

            //CopyTo() copies the values!!!
            iArr1 = new string[good.Count];
            iArr2 = new string[good.Count];
            bad.CopyTo(iArr2, 0);

            if (dic == DicType.Value)
            {
                dicEnt1 = new DictionaryEntry[good.Count];
                good.CopyTo(dicEnt1, 0);
                for (int i = 0; i < good.Count; i++)
                    iArr1[i] = (string)((DictionaryEntry)dicEnt1[i]).Value;

                for (int i = 0; i < iArr1.Length; i++)
                {
                    if (!iArr1[i].Equals(iArr2[i]))
                        hsh1["CopyTo"] = "vanila";
                }
                iArr1 = new string[good.Count + 5];
                iArr2 = new string[good.Count + 5];
                for (int i = 0; i < good.Count; i++)
                    iArr1[i + 5] = (string)((DictionaryEntry)dicEnt1[i]).Value;
                bad.CopyTo(iArr2, 5);
                for (int i = 5; i < iArr1.Length; i++)
                {
                    if (!iArr1[i].Equals(iArr2[i]))
                    {
                        hsh1["CopyTo"] = "5";
                    }
                }
            }
            else if (dic == DicType.Key)
            {
                for (int i = 0; i < iArr1.Length; i++)
                {
                    if (!good.Contains(iArr2[i]))
                        hsh1["CopyTo"] = "Key";
                }
            }

            try
            {
                bad.CopyTo(iArr2, -1);
                hsh1["CopyTo"] = "";
            }
            catch (ArgumentException)
            {
            }
            catch (Exception ex)
            {
                hsh1["CopyTo"] = ex;
            }

            try
            {
                bad.CopyTo(null, 5);
                hsh1["CopyTo"] = "";
            }
            catch (ArgumentNullException)
            {
            }
            catch (Exception ex)
            {
                hsh1["CopyTo"] = ex;
            }

            //Enumerator
            IEnumerator ienm1;
            IEnumerator ienm2;
            ienm1 = good.GetEnumerator();
            ienm2 = bad.GetEnumerator();
            DoTheEnumerator(ienm1, ienm2, hsh1, dic, good);
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:88,代码来源:WrapperTests.cs

示例2: runTest


//.........这里部分代码省略.........
             }
             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");
             }
             catch(ArgumentOutOfRangeException)
             {
             }
             catch(Exception ex)
             {
                 iCountErrors++;
                 Console.WriteLine("Err_7320678dfv! Unexpected exception thrown, " + ex);
             }
             strLoc = "Loc_0734tefgd";
             iCountTestcases++;
             iNumberOfElements = 10;
             slst1 = new SortedList();
             for(int i=iNumberOfElements-1; i>=0;i--)
             {
                 slst1.Add(50 + i, "Value_" + i);
             }
             ar1 = Array.CreateInstance(typeof(DictionaryEntry), iNumberOfElements);
             slst1.CopyTo(ar1, 0);
             for(int i=0; i<slst1.Count;i++)
             {
                 strValue = "Value_" + i;
                 if(!strValue.Equals(((DictionaryEntry)ar1.GetValue(i)).Value)) 
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_004oo! Expected value not returned, " + strValue + " " + ((DictionaryEntry)ar1.GetValue(i)).Value);
                 }
             }
             strLoc = "Loc_7645tgbfgg";
             try
             {
                 iCountTestcases++;
                 ar1 = Array.CreateInstance(typeof(String), iNumberOfElements);
                 slst1.CopyTo(ar1, 0);
                 iCountErrors++;
                 Console.WriteLine("Err_7439dg! Exception not thrown");
             }
             catch(InvalidCastException)
             {
             }
             catch(Exception ex)
             {
                 iCountErrors++;
                 Console.WriteLine("Err_2078sdfd! Unexpected exception thrown, " + ex);
             }
             try
             {
                 iCountTestcases++;
                 slst1.CopyTo(null, 0);
                 iCountErrors++;
                 Console.WriteLine("Err_7439dg! Exception not thrown");
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:67,代码来源:co3953multimethods.cs

示例3: Test01


//.........这里部分代码省略.........
            //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);
            for (int i = 0; i < slst1.Count; i++)
            {
                strValue = "Value_" + i;
                Assert.Equal(strValue, ((DictionaryEntry)ar1.GetValue(i)).Value);
            }

            //paramter stuff
            Assert.Throws<InvalidCastException>(() =>
                             {
                                 ar1 = new String[iNumberOfElements];
                                 slst1.CopyTo(ar1, 0);
                             }
            );

            Assert.Throws<ArgumentNullException>(() =>
                             {
                                 slst1.CopyTo(null, 0);
                             }
            );

            Assert.Throws<ArgumentOutOfRangeException>(() =>
                             {
                                 ar1 = new DictionaryEntry[iNumberOfElements];
                                 slst1.CopyTo(ar1, -1);
                             }
            );

            Assert.Throws<ArgumentException>(() =>
                             {
                                 ar1 = new String[iNumberOfElements];
                                 slst1.CopyTo(ar1, 1);
                             }
            );

            ar1 = new DictionaryEntry[2 * iNumberOfElements];
            slst1.CopyTo(ar1, iNumberOfElements);
            for (int i = 0; i < slst1.Count; i++)
            {
                strValue = "Value_" + i;
                Assert.Equal(strValue, ((DictionaryEntry)ar1.GetValue(iNumberOfElements + i)).Value);
            }
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:101,代码来源:MultiMethodsTests.cs


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