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


C# ArrayList.GetRange方法代码示例

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


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

示例1: TestGetItems

        public void TestGetItems()
        {
            //--------------------------------------------------------------------------
            // Variable definitions.
            //--------------------------------------------------------------------------
            ArrayList arrList = null;
            //
            // Construct array list.
            //
            arrList = new ArrayList();

            // Add items to the lists.
            for (int ii = 0; ii < strHeroes.Length; ++ii)
            {
                arrList.Add(strHeroes[ii]);
            }

            // Verify items added to list.
            Assert.Equal(strHeroes.Length, arrList.Count);

            //Adapter, GetRange, Synchronized, ReadOnly returns a slightly different version of 
            //BinarySearch, Following variable cotains each one of these types of array lists

            ArrayList[] arrayListTypes = {
                                        (ArrayList)arrList.Clone(),
                                        (ArrayList)ArrayList.Adapter(arrList).Clone(),
                                        (ArrayList)ArrayList.FixedSize(arrList).Clone(),
                                        (ArrayList)ArrayList.ReadOnly(arrList).Clone(),
                                        (ArrayList)arrList.GetRange(0, arrList.Count).Clone(),
                                        (ArrayList)ArrayList.Synchronized(arrList).Clone()};

            foreach (ArrayList arrayListType in arrayListTypes)
            {
                arrList = arrayListType;
                //
                // []  Verify get method.
                //
                // Search and verify selected items.
                for (int ii = 0; ii < strHeroes.Length; ++ii)
                {
                    // Verify get.
                    Assert.Equal(0, ((string)arrList[ii]).CompareTo(strHeroes[ii]));
                }

                //
                // []  Invalid Index.
                //
                Assert.Throws<ArgumentOutOfRangeException>(() =>
                {
                    string str = (string)arrList[(int)arrList.Count];
                });

                Assert.Throws<ArgumentOutOfRangeException>(() =>
                {
                    string str = (string)arrList[-1];
                });
            }
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:58,代码来源:PropertyItemTests.cs

示例2: MergeSort

    public ArrayList MergeSort( ArrayList arrIntegers )
    {
        if (arrIntegers.Count == 1)
        {
            return arrIntegers;
        }
        ArrayList arrSortedInt = new ArrayList();
        int middle = (int)arrIntegers.Count/2;

        ArrayList leftArray = arrIntegers.GetRange(0, middle);
        ArrayList rightArray = arrIntegers.GetRange(middle, arrIntegers.Count - middle);

        leftArray =  MergeSort(leftArray);
        rightArray = MergeSort(rightArray);

        int leftptr = 0;
        int rightptr=0;

        for (int i = 0; i < leftArray.Count + rightArray.Count; i++)
        {
            if (leftptr==leftArray.Count)
            {
                arrSortedInt.Add(rightArray[rightptr]);
                rightptr++;
            }
            else if (rightptr==rightArray.Count)
            {
                arrSortedInt.Add(leftArray[leftptr]);
                leftptr++;
            }
            else if ((int)leftArray[leftptr]<(int)rightArray[rightptr])
            {
                //need the cast above since arraylist returns Type object
                arrSortedInt.Add(leftArray[leftptr]);
                leftptr++;
            }
            else
            {
                arrSortedInt.Add(rightArray[rightptr]);
                rightptr++;
            }
        }
        return arrSortedInt;
    }
开发者ID:NikolaNikushev,项目名称:CSharp,代码行数:44,代码来源:Program.cs

示例3: CountInversion

    public ArrayList CountInversion(ArrayList source)
    {
        if (source.Count == 1)
        {
            return source;
        }
        var split = (int)(source.Count / 2); //GetSplitPLace(to - from);
        ArrayList leftArray = source.GetRange(0, split);
        ArrayList rightArray = source.GetRange(split, source.Count - split);
        ArrayList arrSortedInt = new ArrayList();
        leftArray = CountInversion(leftArray);
        rightArray = CountInversion(rightArray);
        int leftptr = 0;
        int rightptr = 0;
        for (int i = 0; i < leftArray.Count + rightArray.Count; i++)
        {
            if (leftptr == leftArray.Count)
            {
                arrSortedInt.Add(rightArray[rightptr]);
                rightptr++;
            }
            else if (rightptr == rightArray.Count)
            {

                arrSortedInt.Add(leftArray[leftptr]);
                leftptr++;
            }
            else if ((int)leftArray[leftptr] < (int)rightArray[rightptr])
            {

                //need the cast above since arraylist returns Type object
                arrSortedInt.Add(leftArray[leftptr]);
                leftptr++;
            }
            else
            {
                inversionCount += (leftArray.Count - leftptr);
                arrSortedInt.Add(rightArray[rightptr]);
                rightptr++;
            }
        }

        return arrSortedInt;
    }
开发者ID:kjakimiec,项目名称:algopq,代码行数:44,代码来源:Inversion.cs

示例4: Merge

    public static ArrayList Merge(ArrayList inputArray)
    {
        if (inputArray.Count == 1)
        {
            return inputArray;
        }
        ArrayList arraySorted = new ArrayList();
        int leftPart = 0;
        int rightPart = 0;
        int middle = (int)inputArray.Count / 2;

        ArrayList leftArray = inputArray.GetRange(0, middle);
        leftArray = Merge(leftArray);
        ArrayList rightArray = inputArray.GetRange(middle, inputArray.Count - middle);
        rightArray = Merge(rightArray);

        for (int i = 0; i < leftArray.Count + rightArray.Count; i++)
        {
            if (leftPart == leftArray.Count)
            {
                arraySorted.Add(rightArray[rightPart]);
                rightPart++;
            }
            else if (rightPart == rightArray.Count)
            {
                arraySorted.Add(leftArray[leftPart]);
                leftPart++;
            }
            else if ((int)leftArray[leftPart] < (int)rightArray[rightPart])
            {
                arraySorted.Add(leftArray[leftPart]);
                leftPart++;
            }
            else
            {
                arraySorted.Add(rightArray[rightPart]);
                rightPart++;
            }
        }
        return arraySorted;
    }
开发者ID:Bvaptsarov,项目名称:Homework,代码行数:41,代码来源:Program.cs

示例5: TestArrayListWrappers

        public void TestArrayListWrappers()
        {
            ArrayList alst1;
            string strValue;
            Array arr1;

            //[] Vanila test case - ToArray returns an array of this. We will not extensively test this method as
            // this is a thin wrapper on Array.Copy which is extensively tested elsewhere
            alst1 = new ArrayList();
            for (int i = 0; i < 10; i++)
            {
                strValue = "String_" + i;
                alst1.Add(strValue);
            }

            ArrayList[] arrayListTypes = {
                                            alst1,
                                            ArrayList.Adapter(alst1),
                                            ArrayList.FixedSize(alst1),
                                            alst1.GetRange(0, alst1.Count),
                                            ArrayList.ReadOnly(alst1),
                                            ArrayList.Synchronized(alst1)};

            foreach (ArrayList arrayListType in arrayListTypes)
            {
                alst1 = arrayListType;
                arr1 = alst1.ToArray(typeof(string));

                for (int i = 0; i < 10; i++)
                {
                    strValue = "String_" + i;
                    Assert.Equal(strValue, (string)arr1.GetValue(i));
                }

                //[] this should be covered in Array.Copy, but lets do it for
                Assert.Throws<InvalidCastException>(() => { arr1 = alst1.ToArray(typeof(int)); });
                Assert.Throws<ArgumentNullException>(() => { arr1 = alst1.ToArray(null); });
            }

            //[]lets try an empty list
            alst1.Clear();
            arr1 = alst1.ToArray(typeof(Object));
            Assert.Equal(0, arr1.Length);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:44,代码来源:ToArrayTests.cs

示例6: PerformActionOnAllArrayListWrappers

        public static void PerformActionOnAllArrayListWrappers(ArrayList arrList, Action<ArrayList> action)
        {
            // Adapter, GetRange, Synchronized, ReadOnly returns a slightly different version of ArrayList.
            // The following variable contains each one of these types of array lists
            ArrayList[] arrayListTypes =
            {
                (ArrayList)arrList.Clone(),
                (ArrayList)arrList.GetRange(0, arrList.Count).Clone(),
                (ArrayList)ArrayList.Adapter(arrList).Clone(),
                (ArrayList)ArrayList.FixedSize(arrList).Clone(),
                (ArrayList)ArrayList.ReadOnly(arrList).Clone(),
                (ArrayList)ArrayList.Synchronized(arrList).Clone()
            };  

            foreach (ArrayList arrListType in arrayListTypes)
            {
                action(arrListType);
            }
        }
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:19,代码来源:Helpers.cs

示例7: TestArrayListWrappers

        public void TestArrayListWrappers()
        {
            //
            // Construct array list.
            //
            ArrayList arrList = new ArrayList();

            // Add items to the lists.
            for (int ii = 0; ii < strHeroes.Length; ++ii)
            {
                arrList.Add(strHeroes[ii]);
            }

            // Verify items added to list.
            Assert.Equal(strHeroes.Length, arrList.Count);

            //Adapter, GetRange, Synchronized, ReadOnly returns a slightly different version of 
            //BinarySearch, Following variable cotains each one of these types of array lists

            ArrayList[] arrayListTypes = {
                                    arrList,
                                    ArrayList.Adapter(arrList),
                                    ArrayList.FixedSize(arrList),
                                    arrList.GetRange(0, arrList.Count),
                                    ArrayList.ReadOnly(arrList),
                                    ArrayList.Synchronized(arrList)};

            int ndx = 0;
            foreach (ArrayList arrayListType in arrayListTypes)
            {
                arrList = arrayListType;

                //
                // []  Use BinarySearch to find selected items.
                //
                // Search and verify selected items.
                for (int ii = 0; ii < strFindHeroes.Length; ++ii)
                {
                    // Locate item.
                    ndx = arrList.BinarySearch(0, arrList.Count, strFindHeroes[ii], this);
                    Assert.True(ndx >= 0);

                    // Verify item.
                    Assert.Equal(0, strHeroes[ndx].CompareTo(strFindHeroes[ii]));
                }

                //
                // []  Locate item in list using null comparer.
                //
                ndx = arrList.BinarySearch(0, arrList.Count, "Batman", null);
                Assert.Equal(2, ndx);

                //
                // []  Locate insertion index of new list item.
                //
                // Append the list.
                ndx = arrList.BinarySearch(0, arrList.Count, "Batgirl", this);
                Assert.Equal(2, ~ndx);

                //
                // []  Bogus Arguments
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.BinarySearch(-100, 1000, arrList.Count, this));
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.BinarySearch(-100, 1000, "Batman", this));
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.BinarySearch(-1, arrList.Count, "Batman", this));
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.BinarySearch(0, -1, "Batman", this));

                Assert.Throws<ArgumentException>(() => arrList.BinarySearch(1, arrList.Count, "Batman", this));
                Assert.Throws<ArgumentException>(() => arrList.BinarySearch(3, arrList.Count - 2, "Batman", this));
            }
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:71,代码来源:BinarySearchTests.cs

示例8: TestArrayListWrappers

        public void TestArrayListWrappers()
        {
            //--------------------------------------------------------------------------
            // Variable definitions.
            //--------------------------------------------------------------------------
            ArrayList arrList = null;

            string[] strHeroes = 
            {
                "Aquaman",
                "Atom",
                "Batman",
                "Black Canary",
                "Captain America",
                "Captain Atom",
                "Catwoman",
                "Cyborg",
                "Flash",
                "Green Arrow",
                "Green Lantern",
                "Hawkman",
                null,
                "Ironman",
                "Nightwing",
                "Robin",
                "SpiderMan",
                "Steel",
                null,
                "Thor",
                "Wildcat",
                null
            };

            //[]  Vanila Contains

            // Construct ArrayList.
            arrList = new ArrayList(strHeroes);

            //Adapter, GetRange, Synchronized, ReadOnly returns a slightly different version of 
            //BinarySearch, Following variable cotains each one of these types of array lists

            ArrayList[] arrayListTypes = {
                                    (ArrayList)arrList.Clone(),
                                    (ArrayList)ArrayList.Adapter(arrList).Clone(),
                                    (ArrayList)ArrayList.FixedSize(arrList).Clone(),
                                    (ArrayList)arrList.GetRange(0, arrList.Count).Clone(),
                                    (ArrayList)ArrayList.Synchronized(arrList).Clone()};

            foreach (ArrayList arrayListType in arrayListTypes)
            {
                arrList = arrayListType;
                for (int i = 0; i < strHeroes.Length; i++)
                {
                    Assert.True(arrList.Contains(strHeroes[i]), "Error, Contains returns false but shour return true at position " + i.ToString());
                }

                if (!arrList.IsFixedSize)
                {
                    //[]  Normal Contains which expects false
                    for (int i = 0; i < strHeroes.Length; i++)
                    {
                        // remove element, if element is in 2 times make sure we remove it completely.
                        for (int j = 0; j < strHeroes.Length; j++)
                        {
                            arrList.Remove(strHeroes[i]);
                        }

                        Assert.False(arrList.Contains(strHeroes[i]), "Error, Contains returns true but should return false at position " + i.ToString());
                    }
                }

                if (!arrList.IsFixedSize)
                {
                    //[]  Normal Contains on empty list
                    arrList.Clear();

                    for (int i = 0; i < strHeroes.Length; i++)
                    {
                        Assert.False(arrList.Contains(strHeroes[i]), "Error, Contains returns true but should return false at position " + i.ToString());
                    }
                }
            }
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:83,代码来源:ContainsTests.cs

示例9: TestSetItems

        public void TestSetItems()
        {
            //--------------------------------------------------------------------------
            // Variable definitions.
            //--------------------------------------------------------------------------
            ArrayList arrList = null;

            //
            // Construct array list.
            //
            arrList = new ArrayList((ICollection)strHeroes);

            //Adapter, GetRange, Synchronized, ReadOnly returns a slightly different version of 
            //BinarySearch, Following variable cotains each one of these types of array lists

            ArrayList[] arrayListTypes = {
                                    (ArrayList)arrList.Clone(),
                                    (ArrayList)ArrayList.Adapter(arrList).Clone(),
                                    (ArrayList)ArrayList.FixedSize(arrList).Clone(),
                                    (ArrayList)arrList.GetRange(0, arrList.Count).Clone(),
                                    (ArrayList)ArrayList.Synchronized(arrList).Clone()};

            foreach (ArrayList arrayListType in arrayListTypes)
            {
                arrList = arrayListType;

                //
                // []  Set item in the array list.
                //
                arrList[0] = "Lone Ranger";

                // Verify set.
                Assert.Equal(0, ((string)arrList[0]).CompareTo("Lone Ranger"));

                //
                // []  Attempt invalid Set using negative index
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => { arrList[-100] = "Lone Ranger"; });

                //
                //  []  Attempt Set using out of range index=1000
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => { arrList[1000] = "Lone Ranger"; });

                //
                //  []  Attempt Set using out of range index=-1
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => { arrList[-1] = "Lone Ranger"; });

                //
                //  []  Attempt Set using null value.
                //
                arrList[0] = null;
                // Verify set.
                Assert.Null(arrList[0]);
            }
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:57,代码来源:PropertyItemTests.cs

示例10: TestDuplicatedItems

        public void TestDuplicatedItems()
        {
            //--------------------------------------------------------------------------
            // Variable definitions.
            //--------------------------------------------------------------------------
            ArrayList arrList = null;

            string[] strHeroes =
            {
                "Aquaman",
                "Atom",
                "Batman",
                "Black Canary",
                "Captain America",
                "Captain Atom",
                "Catwoman",
                "Cyborg",
                "Flash",
                "Green Arrow",
                "Green Lantern",
                "Hawkman",
                "Daniel Takacs",
                "Ironman",
                "Nightwing",
                "Robin",
                "SpiderMan",
                "Steel",
                "Gene",
                "Thor",
                "Wildcat",
                null
            };

            // Construct ArrayList.
            arrList = new ArrayList(strHeroes);

            //Adapter, GetRange, Synchronized, ReadOnly returns a slightly different version of 
            //BinarySearch, Following variable cotains each one of these types of array lists

            ArrayList[] arrayListTypes = {
                                    (ArrayList)arrList.Clone(),
                                    (ArrayList)ArrayList.Adapter(arrList).Clone(),
                                    (ArrayList)arrList.GetRange(0, arrList.Count).Clone(),
                                    (ArrayList)ArrayList.Synchronized(arrList).Clone()};

            foreach (ArrayList arrayListType in arrayListTypes)
            {

                arrList = arrayListType;
                //
                // []  IndexOf an array normal
                //
                for (int i = 0; i < strHeroes.Length; i++)
                {
                    Assert.Equal(i, arrList.IndexOf(strHeroes[i]));
                }


                //[]  Check IndexOf when element is in list twice
                arrList.Clear();
                arrList.Add(null);
                arrList.Add(arrList);
                arrList.Add(null);

                Assert.Equal(0, arrList.IndexOf(null));

                //[]  check for something which does not exist in a list
                arrList.Clear();
                Assert.Equal(-1, arrList.IndexOf(null));
            }
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:71,代码来源:IndexOfTests.cs

示例11: CompareObjects


//.........这里部分代码省略.........
     ienm1 = good.GetEnumerator(50, 50);
     try
     {
         ienm2 = bad.GetEnumerator(50, 50);
         DoIEnumerableTest(ienm1, ienm2, hsh1, false);
     }
     catch
     {
         hsh1["GetEnumerator"] = "(Int32, Int32)";
     }
     try
     {
         bad.GetEnumerator(50, 150);
         hsh1["GetEnumerator"] = "(Int32, Int32)";
     }
     catch(Exception)
     {
     }
     ienm1 = good.GetEnumerator(0, 100);
     try
     {
         ienm2 = bad.GetEnumerator(0, 100);
         good.RemoveAt(0);
         DoIEnumerableTest(ienm1, ienm2, hsh1, true);
     }
     catch
     {
         hsh1["GetEnumerator"] = "(Int32, Int32)";
     }
     good.Clear();
     for(int i=0; i<100; i++)
         good.Add(i);
     if(fVerbose)
         Console.WriteLine("GetRange()");
     ArrayList alst1 = good.GetRange(0, good.Count);
     try
     {
         ArrayList alst2 = bad.GetRange(0, good.Count);
         for(int i=0; i<good.Count; i++)
         {
             if(alst1[i] != alst2[i])
                 hsh1["GetRange"] = i;
         }
     }
     catch
     {
         hsh1["Range"] = "(Int32, Int32)";
     }
     if(bad.Count>0)
     {
         if(fVerbose)
             Console.WriteLine("IndexOf()");
         for(int i=0; i<good.Count; i++)
         {
             if(good.IndexOf(good[i], 0) != bad.IndexOf(good[i], 0))
             {
                 Console.WriteLine(good .Count + " " + bad.Count + " " + good[i] + " " + bad[i] + " " + good.IndexOf(good[i], 0) + " " + bad.IndexOf(good[i], 0));
                 hsh1["IndexOf"] = "(Object, Int32)";
             }
             if(good.IndexOf(good[i], i) != bad.IndexOf(good[i], i))
             {
                 Console.WriteLine("2" + good.IndexOf(good[i], i) + " " + bad.IndexOf(good[i], i));
                 hsh1["IndexOf"] = "(Object, Int32)";
             }
             if(i<(good.Count-1))
             {
开发者ID:ArildF,项目名称:masters,代码行数:67,代码来源:co3966wrappertests.cs

示例12: TestLargeCapacity

        public void TestLargeCapacity()
        {
            //
            //  []  Add a range large enough to increase the capacity of the arrayList by more than a factor of two
            //
            ArrayList arrInsert = new ArrayList();

            for (int i = 0; i < 128; i++)
            {
                arrInsert.Add(-i);
            }

            ArrayList arrList = new ArrayList();

            ArrayList[] arrayListTypes1 = {
                                    (ArrayList)arrList.Clone(),
                                    (ArrayList)ArrayList.Adapter(arrList).Clone(),
                                    (ArrayList)arrList.GetRange(0, arrList.Count).Clone(),
                                    (ArrayList)ArrayList.Synchronized(arrList).Clone()};

            foreach (ArrayList arrayListType in arrayListTypes1)
            {
                arrList = arrayListType;

                arrList.InsertRange(0, arrInsert);

                for (int i = 0; i < arrInsert.Count; i++)
                {
                    Assert.Equal(-i, (int)arrList[i]);
                }
            }
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:32,代码来源:InsertRangeTests.cs

示例13: TestInsertItselfWithRange

        public void TestInsertItselfWithRange()
        {
            //
            // []  Insert itself into array list. with range
            //
            ArrayList arrList = new ArrayList((ICollection)strHeroes);

            ArrayList[] arrayListTypes = new ArrayList[] {
                            (ArrayList)arrList.Clone(),
                            (ArrayList)ArrayList.Adapter(arrList).Clone(),
                            (ArrayList)ArrayList.Synchronized(arrList).Clone()
            };

            int start = 3;
            foreach (ArrayList arrayListType in arrayListTypes)
            {
                arrList = arrayListType;

                // InsertRange values.
                arrList.InsertRange(start, arrList.GetRange(0, arrList.Count));

                // Verify InsertRange.
                for (int ii = 0; ii < arrList.Count; ++ii)
                {
                    string expectedItem;

                    if (ii < start)
                    {
                        expectedItem = strHeroes[ii];
                    }
                    else if (start <= ii && ii - start < strHeroes.Length)
                    {
                        expectedItem = strHeroes[ii - start];
                    }
                    else
                    {
                        expectedItem = strHeroes[(ii - strHeroes.Length)];
                    }

                    Assert.Equal(0, expectedItem.CompareTo((string)arrList[ii]));
                }
            }

        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:44,代码来源:InsertRangeTests.cs

示例14: TestSetRange

        public void TestSetRange()
        {
            //--------------------------------------------------------------------------
            // Variable definitions.
            //--------------------------------------------------------------------------
            ArrayList arrList = null;
            ArrayList arrSetRange = null;
            int start = 3;

            string[] strHeroes =
            {
                "Aquaman",
                "Atom",
                "Batman",
                "Black Canary",
                "Captain America",
                "Captain Atom",
                "Catwoman",
                "Cyborg",
                "Flash",
                "Green Arrow",
                "Green Lantern",
                "Hawkman",
                "Huntress",
                "Ironman",
                "Nightwing",
                "Robin",
                "SpiderMan",
                "Steel",
                "Superman",
                "Thor",
                "Wildcat",
                "Wonder Woman",
            };//22

            string[] strSetRange =
            {
                "Hardware",
                "Icon",
                "Johnny Quest",
                "Captain Sisko",
                "Captain Picard",
                "Captain Kirk",
                "Agent J",
                "Agent K",
                "Space Ghost",
                "Wolverine",
                "Cyclops",
                "Storm",
                "Lone Ranger",
                "Tonto",
                "Supergirl",
            };//15

            // Construct ArrayList.
            arrList = new ArrayList((ICollection)strHeroes);
            arrSetRange = new ArrayList((ICollection)strSetRange);

            //Adapter, GetRange, Synchronized, ReadOnly returns a slightly different version of 
            //BinarySearch, Following variable cotains each one of these types of array lists

            ArrayList[] arrayListTypes = {
                                    (ArrayList)arrList.Clone(),
                                    (ArrayList)ArrayList.Adapter(arrList).Clone(),
                                    (ArrayList)ArrayList.FixedSize(arrList).Clone(),
                                    (ArrayList)arrList.GetRange(0, arrList.Count).Clone(),
                                    (ArrayList)ArrayList.Synchronized(arrList).Clone()};

            foreach (ArrayList arrayListType in arrayListTypes)
            {
                arrList = arrayListType;

                // SetRange entire array list.
                arrList.SetRange(start, arrSetRange);

                // Verify set.
                for (int ii = 0; ii < arrSetRange.Count; ++ii)
                {
                    Assert.Equal(0, ((string)arrList[start + ii]).CompareTo((String)arrSetRange[ii]));
                }

                //
                // []  Attempt invalid SetRange using collection that exceed valid range.
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.SetRange(start, arrList));

                //
                // []  Attempt invalid SetRange using negative index
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.SetRange(-100, arrSetRange));

                //
                //  []  Attempt SetRange using out of range index
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.SetRange(1000, arrSetRange));

                //
                //  []  Attempt SetRange using null collection.
                //
                Assert.Throws<ArgumentNullException>(() => arrList.SetRange(0, null));
//.........这里部分代码省略.........
开发者ID:noahfalk,项目名称:corefx,代码行数:101,代码来源:GetSetRangeTests.cs

示例15: TestArrayListWrappers

        public void TestArrayListWrappers()
        {
            //--------------------------------------------------------------------------
            // Variable definitions.
            //--------------------------------------------------------------------------
            ArrayList arrList = null;
            String[] arrCopy = null;

            arrList = new ArrayList(strHeroes);

            //Adapter, GetRange, Synchronized, ReadOnly returns a slightly different version of 
            //BinarySearch, Following variable cotains each one of these types of array lists

            ArrayList[] arrayListTypes = {
                                    (ArrayList)arrList.Clone(),
                                    (ArrayList)ArrayList.Adapter(arrList).Clone(),
                                    (ArrayList)arrList.GetRange(0, arrList.Count).Clone(),
                                    (ArrayList)ArrayList.Synchronized(arrList).Clone()};

            foreach (ArrayList arrayListType in arrayListTypes)
            {
                arrList = arrayListType;
                //
                // []  CopyTo an array normal
                //
                arrCopy = new String[strHeroes.Length];
                arrList.CopyTo(arrCopy, 0);

                for (int i = 0; i < arrCopy.Length; i++)
                {
                    Assert.Equal<string>(strHeroes[i], arrCopy[i]);
                }

                //[]  Normal Copy Test 2 - copy 0 elements
                arrList.Clear();
                arrList.Add(null);
                arrList.Add(arrList);
                arrList.Add(null);
                arrList.Remove(null);
                arrList.Remove(null);
                arrList.Remove(arrList);

                Assert.Equal(0, arrList.Count);

                arrCopy = new String[strHeroes.Length];
                // put some elements in arrCopy that should not be overriden
                for (int i = 0; i < strHeroes.Length; i++)
                {
                    arrCopy[i] = strHeroes[i];
                }

                //copying 0 elements into arrCopy
                arrList.CopyTo(arrCopy, 1);

                // check to make sure sentinals stay the same
                for (int i = 0; i < arrCopy.Length; i++)
                {
                    Assert.Equal<string>(strHeroes[i], arrCopy[i]);
                }

                //[]  Normal Copy Test 3 - copy 0 elements from the end
                arrList.Clear();
                Assert.Equal(0, arrList.Count);

                arrCopy = new String[strHeroes.Length];

                // put some elements in arrCopy that should not be overriden
                for (int i = 0; i < strHeroes.Length; i++)
                {
                    arrCopy[i] = strHeroes[i];
                }

                //copying 0 elements into arrCopy, into last valid index of arrCopy
                arrList.CopyTo(arrCopy, arrCopy.Length - 1);

                // check to make sure sentinals stay the same
                for (int i = 0; i < arrCopy.Length; i++)
                {
                    Assert.Equal<string>(strHeroes[i], arrCopy[i]);
                }

                //[]  Copy so that exception should be thrown
                arrList.Clear();
                arrCopy = new String[2];

                //copying 0 elements into arrCopy
                arrList.CopyTo(arrCopy, arrCopy.Length);

                // []  Copy so that exception should be thrown 2
                arrList.Clear();
                Assert.Equal(0, arrList.Count);

                arrCopy = new String[0];
                //copying 0 elements into arrCopy
                arrList.CopyTo(arrCopy, 0);

                // []  CopyTo with negative index
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.CopyTo(arrCopy, -1));

                // []  CopyTo with array with index is not large enough
//.........这里部分代码省略.........
开发者ID:er0dr1guez,项目名称:corefx,代码行数:101,代码来源:CopyToTests.cs


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