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


C# ArrayList.SetRange方法代码示例

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


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

示例1: CompareObjects


//.........这里部分代码省略.........
             if(bad.Count>0)
             {
                 for(int i=0; i<(bad.Count-1); i++)
                 {
                     if(((String)bad[i]).CompareTo(((String)bad[i+1])) >= 0)
                         hsh1["Sort"] = "(IComparer)";
                 }			
                 for(int i=0; i<bad.Count; i++)
                 {
                     if(bad.BinarySearch(bad[i], new CaseInsensitiveComparer()) != i)
                         hsh1["BinarySearch"] = "(Object, IComparer)";
                 }
             }
             bad.Reverse();			
             good.Clear();
             for(int i=65; i<91; i++)
                 good.Add(((Char)i).ToString());
             if(bad.Count>0)
             {
                 for(int i=0; i<good.Count; i++)
                 {
                     if(bad.BinarySearch(0, bad.Count, bad[i], new CaseInsensitiveComparer()) != i)
                         hsh1["BinarySearch"] = "(Int32, Int32, Object, IComparer)";
                 }
             }
         }
         catch(Exception)
         {
         }
         good.Clear();
         for(int i=0; i<100; i++)
             good.Add(i);
         if(fVerbose)
             Console.WriteLine("SetRange()");
         Queue que = new Queue();
         for(int i=0; i<100; i++)
             que.Enqueue(i+5000);
         try
         {
             bad.SetRange(0, que);
         }
         catch(Exception ex)
         {
             hsh1["SetRange"] = "Copy_ExceptionType, " + ex.GetType().Name;
         }
         for(int i=bad.Count; i<bad.Count; i++)
         {
             if((Int32)bad[i] != (i + 5000))
             {
                 hsh1["SetRange"] = i;
             }
         }
     }
     else
     {
         good.Clear();
         for(int i=100; i>0; i--)
             good.Add(i);
         try
         {
             bad.Sort();
             hsh1["Sort"] = "Copy";
         }
         catch(NotSupportedException)
         {
         }
开发者ID:ArildF,项目名称:masters,代码行数:67,代码来源:co3966wrappertests.cs

示例2: 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

示例3: CompareObjects


//.........这里部分代码省略.........
                        if (bad.BinarySearch(bad[i], new CaseInsensitiveComparer()) != i)
                            hsh1["BinarySearch"] = "(Object, IComparer)";
                    }
                }
                bad.Reverse();

                good.Clear();
                for (int i = 65; i < 91; i++)
                    good.Add(((Char)i).ToString());

                if (bad.Count > 0)
                {
                    for (int i = 0; i < good.Count; i++)
                    {
                        if (bad.BinarySearch(0, bad.Count, bad[i], new CaseInsensitiveComparer()) != i)
                            hsh1["BinarySearch"] = "(int, int, Object, IComparer)";
                    }
                }
            }
            catch (Exception)
            {
            }

            good.Clear();
            for (int i = 0; i < 100; i++)
                good.Add(i);

            Queue que = new Queue();
            for (int i = 0; i < 100; i++)
                que.Enqueue(i + 5000);

            try
            {
                bad.SetRange(0, que);
            }
            catch (Exception ex)
            {
                hsh1["SetRange"] = "Copy_ExceptionType, " + ex.GetType().Name;
            }
            for (int i = bad.Count; i < bad.Count; i++)
            {
                if ((int)bad[i] != (i + 5000))
                {
                    hsh1["SetRange"] = i;
                }
            }
        }
        else
        {
            //we make sure that the above methods throw here
            good.Clear();
            for (int i = 100; i > 0; i--)
                good.Add(i);

            try
            {
                bad.Sort();
                hsh1["Sort"] = "Copy";
            }
            catch (NotSupportedException)
            {
            }
            catch (Exception)
            {
                hsh1["Sort"] = "Copy_ExceptionType";
            }
开发者ID:noahfalk,项目名称:corefx,代码行数:67,代码来源:WrapperTests.cs

示例4: runTest

 public virtual bool runTest()
 {
     int iCountErrors = 0;
     int iCountTestcases = 0;
     Console.Error.WriteLine( strName + ": " + strTest + " runTest started..." );
     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",
     };
     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",
     };
     do
     {
         ++iCountTestcases;
         Console.Error.WriteLine( "[]  Construct ArrayList" );
         try
         {
             arrList = new ArrayList( (ICollection) strHeroes );
             if ( arrList == null )
             {
                 Console.WriteLine( strTest+ "E_101: Failed to construct new ArrayList" );
                 ++iCountErrors;
                 break;
             }
             arrSetRange = new ArrayList( (ICollection) strSetRange );
             if ( arrSetRange == null )
             {
                 Console.WriteLine( strTest+ "E_102: Failed to construct new ArrayList arrSetRange" );
                 ++iCountErrors;
                 break;
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine( strTest+ "E_10001: Unexpected Exception: " + ex.ToString() );
             ++iCountErrors;
             break;
         }
         ++iCountTestcases;
         Console.Error.WriteLine( "[]  Set range in the array list" );
         try
         {
             arrList.SetRange( start, arrSetRange );
             for ( int ii = 0; ii < arrSetRange.Count; ++ii )
             {
                 if ( ((String)arrList[start+ii]).CompareTo( (String)arrSetRange[ii] ) != 0 )
                 {
                     String strInfo = strTest + " error: ";
                     strInfo = strInfo + "Expected hero <" + (String)arrList[start+ii] + "> ";
                     strInfo = strInfo + "Returned hero <"+ (String)arrSetRange[ii] + "> ";
                     Console.WriteLine( strTest+ "E_202: " + strInfo );
                     ++iCountErrors;
                     break;
                 }
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine( strTest+ "E_10002: Unexpected Exception: " + ex.ToString() );
             ++iCountErrors;
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co2488setrange.cs

示例5: TestArrayListSetRangeOverflow

	public void TestArrayListSetRangeOverflow () 
			{
				ArrayList arrayList = new ArrayList ();
				arrayList.Add (this);
				try
				{
					arrayList.SetRange (Int32.MaxValue, new ArrayList ());
					Fail("Should have thrown an ArgumentOutOfRangeException");
				}
				catch(ArgumentOutOfRangeException e)
				{
				}
				catch(Exception e)
				{
					Fail("Should have thrown an ArgumentOutOfRangeException instead of " + 
							e.GetType().Name);
				}
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:18,代码来源:TestArrayList.cs

示例6: optimizeGesture

    static ArrayList optimizeGesture(ArrayList pointArray, int maxPoints)
    {
        // take all the points in the gesture and finds the correct points compared with distance and the maximun value of points

        // calc the interval relative the length of the gesture drawn by the user
        float interval = calcTotalGestureLength(pointArray) / (maxPoints - 1);

        // use the same starting point in the new array from the old one.
        ArrayList optimizedPoints = new ArrayList();
        optimizedPoints.Add(pointArray[0]);

        float tempDistance = 0.0f;

        // run through the gesture array. Start at i = 1 because we compare point two with point one)
        for (int i = 1; i < pointArray.Count; ++i)
        {
            float currentDistanceBetween2Points = calcDistance((Vector2)pointArray[i - 1], (Vector2)pointArray[i]);

            if ((tempDistance + currentDistanceBetween2Points) >= interval)
            {
                Vector2 v1 = (Vector2)pointArray[i - 1];
                Vector2 v = (Vector2)pointArray[i];

                // the calc is: old pixel + the differens of old and new pixel multiply
                float newX = v1.x + ((interval - tempDistance) / currentDistanceBetween2Points) * (v.x - v1.x);
                float newY = v1.y + ((interval - tempDistance) / currentDistanceBetween2Points) * (v.y - v1.y);

                // create new point
                Vector2 newPoint = new Vector2(newX, newY);

                // set new point into array
                optimizedPoints.Add(newPoint);

                ArrayList temp = pointArray.GetRange(i, pointArray.Count - i - 1);
                Vector2 last = (Vector2)pointArray[pointArray.Count - 1];
                pointArray.SetRange(i + 1, temp);
                pointArray.Add(last);
                //pointArray.InsertRange(i + 1, temp);
                pointArray.Insert(i, newPoint);

                tempDistance = 0.0f;
            }
            else
            {
                // the point was too close to the last point compared with the interval,. Therefore the distance will be stored for the next point to be compared.
                tempDistance += currentDistanceBetween2Points;
            }
        }

        // Rounding-errors might happens. Just to check if all the points are in the new array
        if (optimizedPoints.Count == maxPoints - 1)
        {
            Vector2 v = (Vector2)pointArray[pointArray.Count - 1];
            optimizedPoints.Add(new Vector2(v.x, v.y));
        }

        return optimizedPoints;
    }
开发者ID:Duelist,项目名称:Project-Reach,代码行数:58,代码来源:GestureRecognizer.cs


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