Example #1
0
        public void drawOppKnocks(Player p)
        {
            int cardTaken = (int)potLuck[rand.Next(0, potLuck.Capacity)];

            opportunityKnocks.TrimToSize();
            oppKnocks(cardTaken, p);
        }
Example #2
0
        private void CommandWorker()
        {
            //lock (sync)
            {
                while (cmdQueue.Count > 0)
                {
                    NXTCommand cmd = (NXTCommand)cmdQueue[0];

                    if (!SocketSend(cmd.command))
                    {
                        cmdArchive.Add(cmd);
                        cmdQueue.RemoveAt(0);
                        cmdQueue.TrimToSize();
                        continue;
                    }

                    if (cmd.UpdateStatus())
                    {
                        SocketReceive(cmd.reply);
                    }

                    ProcessReply(cmd);

                    cmdArchive.Add(cmd);
                    cmdQueue.RemoveAt(0);
                    cmdQueue.TrimToSize();

                    /*
                     * byte nError = cmd.reply[2];
                     * if (nError > 0)
                     *  throw new NXTException(GetError(nError));
                     */
                }
            }
        }
Example #3
0
        public void drawPotLuck(Player p)
        {
            int cardTaken = (int)potLuck[rand.Next(0, potLuck.Capacity)];

            potLuck.TrimToSize();
            pot(cardTaken, p);
        }
Example #4
0
        public void tumBaglantiSil()
        {
            if (grafiknesne != null)
            {
                grafiknesne = frm1.CreateGraphics();
                grafiknesne.Clear(Color.White);
                grafiknesne.Dispose();
            }
            top1.Clear();
            top2.Clear();
            left1.Clear();
            left2.Clear();
            yukseklik1.Clear();
            yukseklik2.Clear();
            genislik1.Clear();
            genislik2.Clear();
            baglanti.Clear();

            top1.TrimToSize();
            top2.TrimToSize();
            left1.TrimToSize();
            left2.TrimToSize();
            yukseklik1.TrimToSize();
            yukseklik2.TrimToSize();
            genislik1.TrimToSize();
            genislik2.TrimToSize();
            baglanti.TrimToSize();
        }
Example #5
0
        public virtual void Clear()
        {
            if (m_cMyPane != null)
            {
                while (m_cMyPane.CurveList.Count != 0)
                {
                    CurveItem curve = m_cMyPane.CurveList[0] as CurveItem;

                    if (curve == null)
                    {
                        return;
                    }

                    m_cMyPane.CurveList.Remove(curve);
                }

                m_cMyPane.CurveList.TrimExcess();

                if (m_alDatainGraph != null)
                {
                    m_alDatainGraph.Clear();
                    m_alDatainGraph.TrimToSize();
                }
            }
            ZGControl.ZoomOutAll(m_cMyPane);
        }
Example #6
0
 // Allows you to see the top card without removing it.
 public Card GetTopCard()
 {
     cardStack.TrimToSize();
     if (cardStack.Count == 0)
     {
         return(null);
     }
     return((Card)cardStack [cardStack.Count - 1]);
 }
        }// end constructor

        // Method to get all {} tags in a file
        protected override String [] GetTags(String fileName)
        {
            // Temp array list for tags. To be converted to array.
            ArrayList tagList = new ArrayList();

            // The array to be built and returned
            String[] tagStrings = null;

            // Open the iput file. BE careful with the encoding
            StreamReader inputFile = new StreamReader(File.Open(fileName,
                                                                FileMode.OpenOrCreate, FileAccess.Read),
                                                      Encoding.GetEncoding(1256)); // Encoding is windows-1256 like in Notepad ++: Encoding-->Character Sets --> Arabic--> Windows-1256

            logger.LogTrace("Getting tags of: " + fileName);

            // Read input file in one string
            String inputTxt = inputFile.ReadToEnd();

            if (inputTxt != "")
            {
                // Make regular expression to catch anything between {*} this is the tag
                String tagExpression = @"{.*?}";

                // Match all tags
                MatchCollection tags = Regex.Matches(inputTxt, tagExpression);

                // Insert them in the array list
                foreach (Match tag in tags)
                {
                    tagList.Add(tag.Value);
                }// end foreach

                tagList.TrimToSize(); // Final size decided
                tagStrings = (String[])tagList.ToArray(tagList[0].GetType());

                try
                {
                    tagList.TrimToSize(); // Final size decided
                    tagStrings = (String[])tagList.ToArray(tagList[0].GetType());
                }
                catch (ArgumentOutOfRangeException)
                {
                    logger.LogError("File " + fileName + " is empty", ErrorCode.FILE_IS_EMPTY);
                } //end try-catch*/
            }     // end if(inputTxt != "")
            else
            {
                logger.LogError("File " + fileName + " is empty", ErrorCode.FILE_IS_EMPTY);
                tagStrings = null;
            } // end else

            inputFile.Close();

            // Return the full list of tags
            return(tagStrings);
        } // end GetTags()
Example #8
0
 void OnTriggerEnter2D(Collider2D col)
 {
     if (col.gameObject.CompareTag("NinjaCat"))
     {
         enemies.Add(col.gameObject);
         enemies.TrimToSize();
         delete = true;
         Debug.Log("Enemy Spotted");
     }
 }
Example #9
0
        /// <summary>
        /// Calculates the length of the given ArrayList representation of the Pdu and
        /// inserts this length into the appropriate spot in the Pdu.  This will call
        /// TrimToSize()on the ArrayList-the caller need not do it.
        /// </summary>
        /// <param name="pdu">The protocol data unit to calculate the
        /// length for.</param>
        /// <returns>The Pdu with the length inserted, trimmed to size.</returns>
        protected static ArrayList InsertLengthIntoPdu(ArrayList pdu)
        {
            pdu.TrimToSize();
            uint commandLength = (uint)(4 + pdu.Count);
            uint reqLenH2N     = UnsignedNumConverter.SwapByteOrdering(commandLength);

            byte[] reqLenArray = BitConverter.GetBytes(reqLenH2N);
            //insert into the Pdu
            pdu.InsertRange(0, reqLenArray);
            pdu.TrimToSize();

            return(pdu);
        }
Example #10
0
    public static void Main()
    {
        // Creates and initializes a new ArrayList.
        ArrayList myAL = new ArrayList();

        myAL.Add("The");
        myAL.Add("quick");
        myAL.Add("brown");
        myAL.Add("fox");
        myAL.Add("jumped");

        // Displays the count, capacity and values of the ArrayList.
        Console.WriteLine("Initially,");
        Console.WriteLine("   Count    : {0}", myAL.Count);
        Console.WriteLine("   Capacity : {0}", myAL.Capacity);
        Console.Write("   Values:");
        PrintValues(myAL);

        // Trim the ArrayList.
        myAL.TrimToSize();

        // Displays the count, capacity and values of the ArrayList.
        Console.WriteLine("After TrimToSize,");
        Console.WriteLine("   Count    : {0}", myAL.Count);
        Console.WriteLine("   Capacity : {0}", myAL.Capacity);
        Console.Write("   Values:");
        PrintValues(myAL);

        // Clear the ArrayList.
        myAL.Clear();

        // Displays the count, capacity and values of the ArrayList.
        Console.WriteLine("After Clear,");
        Console.WriteLine("   Count    : {0}", myAL.Count);
        Console.WriteLine("   Capacity : {0}", myAL.Capacity);
        Console.Write("   Values:");
        PrintValues(myAL);

        // Trim the ArrayList again.
        myAL.TrimToSize();

        // Displays the count, capacity and values of the ArrayList.
        Console.WriteLine("After the second TrimToSize,");
        Console.WriteLine("   Count    : {0}", myAL.Count);
        Console.WriteLine("   Capacity : {0}", myAL.Capacity);
        Console.Write("   Values:");
        PrintValues(myAL);
    }
Example #11
0
            public UnionCollection(ICollection c1, ICollection c2)
            {
                Hashtable table1 = new Hashtable(c1.Count);

                foreach (object obj in c1)
                {
                    if (!table1.Contains(obj))
                    {
                        table1.Add(obj, null);
                    }
                }

                Hashtable table2 = new Hashtable(c2.Count);

                foreach (object obj in c2)
                {
                    if (!table2.Contains(obj))
                    {
                        table2.Add(obj, null);
                    }
                }

                // building the union
                union = new ArrayList(Math.Max(table1.Count, table2.Count));
                union.AddRange(table1.Keys);
                foreach (object obj in c2)
                {
                    if (!table1.Contains(obj))
                    {
                        union.Add(obj);
                    }
                }

                union.TrimToSize();
            }
Example #12
0
        //用“埃氏筛法”求2~ 100以内的素数。2~ 100以内的数,先去掉2的倍数,再去掉3的倍数,再
        //去掉4的倍数,以此类推...最后剩下的就是素数。
        static void Main(string[] args)
        {
            ArrayList array = new ArrayList();

            int[] divisor = new int[9];
            for (int i = 2; i <= 100; i++)
            {
                array.Add(i);
                if (i <= 10)
                {
                    divisor[i - 2] = i;
                }
            }
            foreach (int i in divisor)
            {
                for (int j = 0; j < array.Capacity; j++)
                {
                    if (Convert.ToInt32(array[j]) % i == 0)
                    {
                        array.RemoveAt(j);
                    }
                    array.TrimToSize();
                }
            }
            foreach (int i in array)
            {
                Console.Write(i + "   ");
            }
            Console.ReadLine();
        }
Example #13
0
        /// <summary>
        /// Spins through the <see cref="InstructionCollection"/> and creates an array of bytes
        /// that is then copied into Memory by <see cref="OS.createProcess"/>
        /// </summary>
        /// <returns>Array of bytes representing the <see cref="Program"/> in memory</returns>
        unsafe public byte[] GetMemoryImage()
        {
            ArrayList arrayListInstr = new ArrayList();

            foreach (Instruction instr in instructions)
            {
                // Instructions are one byte
                arrayListInstr.Add((byte)instr.OpCode);

                // Params are Four Bytes
                if (instr.Param1 != uint.MaxValue)
                {
                    byte[] paramBytes = CPU.UIntToBytes(instr.Param1);
                    for (int i = 0; i < paramBytes.Length; i++)
                    {
                        arrayListInstr.Add(paramBytes[i]);
                    }
                }

                if (instr.Param2 != uint.MaxValue)
                {
                    byte[] paramBytes = CPU.UIntToBytes(instr.Param2);
                    for (int i = 0; i < paramBytes.Length; i++)
                    {
                        arrayListInstr.Add(paramBytes[i]);
                    }
                }
            }

            // Create and array of bytes and return the instructions in it
            arrayListInstr.TrimToSize();
            byte[] arrayInstr = new byte[arrayListInstr.Count];
            arrayListInstr.CopyTo(arrayInstr);
            return(arrayInstr);
        }
Example #14
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            // Code Inserted Automatically

            #region Code Inserted Automatically

            this.Cursor = Cursors.WaitCursor;

            #endregion Code Inserted Automatically


            const string METHOD_NAME = THIS + ".btnOK_Click()";
            try
            {
                // get all checked item and add to arraylist
                foreach (int intIndex in chlList.CheckedIndices)
                {
                    marrReturnsList.Add(tblData.Rows[intIndex][strValueMember]);
                }
                marrReturnsList.TrimToSize();
                // close the form
                this.Close();
            }
            catch (PCSException ex)
            {
                // displays the error message.
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                // log message.
                try
                {
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                // displays the error message.
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
                // log message.
                try
                {
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }

            // Code Inserted Automatically

            #region Code Inserted Automatically

            this.Cursor = Cursors.Default;

            #endregion Code Inserted Automatically
        }
Example #15
0
        // get stock name lookup results
        public ArrayList GetStockSymbolLookup(string name)
        {
            string lookup_url = @"http://finance.yahoo.com/lookup?s=" + name.Replace(suffix, "") + @"&t=S&m=ALL";

            XmlDocument xml = cap.DownloadXmlWebPage(lookup_url);

            if (xml == null)
            {
                return(null);
            }

            ArrayList symbol_list = new ArrayList();

            symbol_list.Capacity = 256;

            for (int i = 0; i < symbol_list.Capacity; i++)
            {
                string entry = "";

                XmlNode nd, root_node = prs.GetXmlNodeByPath(xml.FirstChild, @"body\div\br\br\table\tr(3)\td\table(2)\tr(3)\td\table\tr\td\table\tr(" + (i + 2).ToString() + @")");
                if (root_node == null)
                {
                    break;
                }

                // stock name
                nd = prs.GetXmlNodeByPath(root_node, @"td(2)");
                if (nd == null)
                {
                    break;
                }
                entry = nd.InnerText.Replace('(', '[').Replace(')', ']');

                // stock ticker
                nd = prs.GetXmlNodeByPath(root_node, @"td(1)\a");
                if (nd == null)
                {
                    break;
                }

                int x = nd.InnerText.IndexOf('.');
                if (x >= 0)
                {
                    entry += nd.InnerText.Substring(0, x);
                }
                else
                {
                    entry += " (" + nd.InnerText + ")";
                }

                // add name + ticker entry
                if (entry.Contains(suffix))
                {
                    symbol_list.Add(entry.Replace(suffix, ""));
                }
            }

            symbol_list.TrimToSize();
            return(symbol_list);
        }
Example #16
0
        public void Browse(OPCBrowseType p_Type, out ArrayList p_Lst)
        {
            p_Lst = null;
            UCOMIEnumString l_Enumerator;

            BrowseOPCItemIDs(p_Type, "", VarEnum.VT_EMPTY, 0, out l_Enumerator);
            if (l_Enumerator == null)
            {
                return;
            }

            p_Lst = new ArrayList(500);
            int l_Cft;

            string[] l_StrF = new string[100];
            int      l_HResult;

            do
            {
                l_Cft     = 0;
                l_HResult = l_Enumerator.Next(100, l_StrF, out l_Cft);
                if (l_Cft > 0)
                {
                    for (int i = 0; i < l_Cft; ++i)
                    {
                        p_Lst.Add(l_StrF[i]);
                    }
                }
            }while (l_HResult == HResults.S_OK);

            Marshal.ReleaseComObject(l_Enumerator);
            l_Enumerator = null;
            p_Lst.TrimToSize();
        }
Example #17
0
        private void button4_Click(object sender, EventArgs e)
        {
            int nSel = listBox1.SelectedIndex;

            if (nSel < 0)
            {
                lbmsg.Text = "请选择要删除的用户...";
                return;
            }
            if (MessageBox.Show("确定删除用户[" + listBox1.Text + "]?删除不可恢复", "信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.OK)
            {
                lbmsg.Text = "正在删除用户信息...";
                lbmsg.Refresh();

                LgUser lu     = (LgUser)m_arryUsers[nSel];
                string strSql = "DELETE FROM BT_USER_REGISTER WHERE ID=" + lu.sIndex;
                if (m_pDbMSSql.ExecuteSql(strSql))
                {
                    listBox1.Items.RemoveAt(nSel);
                    m_arryUsers.RemoveAt(nSel);
                    m_arryUsers.TrimToSize();

                    textBox1.Text = "";
                    textBox2.Text = "";

                    lbmsg.Text = "完成删除用户信息";
                }
                else
                {
                    lbmsg.Text = "删除成败";
                }
            }
        }
Example #18
0
            public InterCollection(ICollection c1, ICollection c2)
            {
                // swap in order to have <c>c1.Count <= c2.Count</c>
                if (c1.Count > c2.Count)
                {
                    ICollection c1Bis = c1;
                    c1 = c2;
                    c2 = c1;
                }

                Hashtable table = new Hashtable(c1.Count);

                foreach (object obj in c1)
                {
                    if (!table.Contains(obj))
                    {
                        table.Add(obj, null);
                    }
                }

                // building the intersection
                intersection = new ArrayList();
                foreach (object obj in c2)
                {
                    if (table.Contains(obj))
                    {
                        intersection.Add(obj);
                        table.Remove(obj);
                    }
                }

                intersection.TrimToSize();
            }
Example #19
0
        public void Browse(OPCBROWSETYPE typ, out ArrayList lst)
        {
            IEnumString str;

            lst = null;
            this.BrowseOPCItemIDs(typ, "", VarEnum.VT_EMPTY, 0, out str);
            if (str != null)
            {
                int num2;
                lst = new ArrayList(500);
                string[] rgelt = new string[100];
                do
                {
                    //int pceltFetched = 0;
                    IntPtr pceltFetchedPtr = new IntPtr(0);
                    num2 = str.Next(100, rgelt, pceltFetchedPtr);
                    int pceltFetched = pceltFetchedPtr.ToInt32();
                    if (pceltFetched > 0)
                    {
                        for (int i = 0; i < pceltFetched; i++)
                        {
                            lst.Add(rgelt[i]);
                        }
                    }
                }while (num2 == 0);
                int num4 = Marshal.ReleaseComObject(str);
                str = null;
                lst.TrimToSize();
            }
        }
Example #20
0
 /// <summary>
 /// Removes The Given Rule Object From RuleSet
 /// </summary>
 /// <param name="rule">The Rule Object To Be Removed</param>
 /// <returns></returns>
 public bool RemoveRule(Rule rule)
 {
     rule.BaseRuleList = null;
     Rules.Remove(rule);
     Rules.TrimToSize();
     return(true);
 }
Example #21
0
        void UnderstandingCollection()
        {
            ArrayList al = new ArrayList();

            al.Add(10);
            al.Add(12.3f);
            al.Add("Hello");
            al.Add(123.2);
            al.Add(new Object());
            al.Add("Hello");
            foreach (var item in al)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("The capacity of the collection is " + al.Capacity);
            al.TrimToSize();
            Console.WriteLine("The capacity of the collection after trim is " + al.Capacity);
            al.Add("Hello");

            double sum = 0;
            //foreach (var item in al)
            //{
            //sum += Convert.ToDouble(item);

            // }
        }
Example #22
0
        /// <summary>
        ///   Returns all menu entries matching the name in this applicaiton menu
        /// </summary>
        /// <param name="entryName">Sring Entry name to be searched</param>
        /// <param name="pulldownMenu">Current pulldown menu</param>
        /// <returns>List of MenuEntries matching the entry Name</returns>
        public ArrayList GetMatchingMenuValues(String entryName, MgMenu pulldownMenu)
        {
            ArrayList   matchingMnuValues = new ArrayList(); // Can't use List<T> - may hold MenuEntry or MgValue
            IEnumerator iMgMenu           = menus.GetEnumerator();

            while (iMgMenu.MoveNext())
            {
                bool isPulldown;

                MgMenu mgmenu = (MgMenu)iMgMenu.Current;
                if (mgmenu == pulldownMenu)
                {
                    isPulldown = true;
                }
                else
                {
                    isPulldown = false;
                }

                IEnumerator iMenuEntry = mgmenu.iterator();
                BuildMatchingMenuValues(entryName, iMenuEntry, isPulldown, matchingMnuValues);
            }

            matchingMnuValues.TrimToSize();
            return(matchingMnuValues);
        }
Example #23
0
            public MinusCollection(ICollection c1, ICollection c2)
            {
                Hashtable table1 = new Hashtable(c1.Count);

                foreach (object obj in c1)
                {
                    if (!table1.Contains(obj))
                    {
                        table1.Add(obj, null);
                    }
                }

                Hashtable table2 = new Hashtable(c2.Count);

                foreach (object obj in c2)
                {
                    if (!table2.Contains(obj))
                    {
                        table2.Add(obj, null);
                    }
                }

                // building minus collection
                minus = new ArrayList(Math.Max(c1.Count - c2.Count, 10));
                foreach (object obj in table1.Keys)
                {
                    if (!table2.Contains(obj))
                    {
                        minus.Add(obj);
                    }
                }

                minus.TrimToSize();
            }
Example #24
0
        /// <summary>
        /// Iterates through the hashtable, gathering the tag, length, and
        /// value as it goes.  For each entry, it encodes the TLV into a byte
        /// array.  It is assumed that the tags and length are already in network
        /// byte order.
        /// </summary>
        /// <returns>An ArrayList consisting of byte array entries, each of which
        /// is a TLV.  Returns an empty ArrayList if the TLV table is empty.</returns>
        public ArrayList GenerateByteEncodedTlv()
        {
            if (tlvTable == null || tlvTable.Count <= 0)
            {
                return(new ArrayList(0));
            }

            ArrayList             tlvs     = new ArrayList();
            IDictionaryEnumerator iterator = tlvTable.GetEnumerator();
            ArrayList             elem     = new ArrayList();

            while (iterator.MoveNext())
            {
                elem.Clear();
                //tag-2 bytes
                elem.AddRange(BitConverter.GetBytes(((UInt16)iterator.Key)));
                //length-2 bytes
                byte[] nextVal   = (byte[])iterator.Value;
                UInt16 tlvLength = UnsignedNumConverter.SwapByteOrdering(((UInt16)(nextVal).Length));
                elem.AddRange(BitConverter.GetBytes(tlvLength));
                //value
                elem.AddRange(nextVal);
                elem.TrimToSize();
                //copy it over to a byte array
                tlvs.Add(elem.ToArray(typeof(byte)));
            }

            tlvs.TrimToSize();

            return(tlvs);
        }
    protected void lnkDelete_Command(object sender, CommandEventArgs e)
    {
        string articleCode = e.CommandArgument.ToString();

        SaveOrder(grdOrder);
        if (Session["order"] != null)
        {
            cartTable = (ArrayList)Session["order"];
            IEnumerator enu = cartTable.GetEnumerator();
            while (enu.MoveNext())
            {
                Order order = (Order)enu.Current;
                if (order.articlecode.ToString().Equals(articleCode))
                {
                    cartTable.Remove(order);
                    cartTable.TrimToSize();

                    break;
                }
            }
            Session["order"] = cartTable;
            InitCartList();
            LoadDatagrid();
        }
    }
Example #26
0
        /// <summary>
        /// Creates the bytes after the destination address bytes.  This also inserts the TLV
        /// table data.  Common to both submit and submit multiple.
        /// </summary>
        /// <returns>The bytes in the Pdu before the destination address(es).</returns>
        protected ArrayList GetBytesAfterDestination()
        {
            ArrayList pdu = new ArrayList();

            pdu.Add(EsmClass);
            pdu.Add((byte)ProtocolId);
            pdu.Add((byte)PriorityFlag);
            pdu.AddRange(SmppStringUtil.ArrayCopyWithNull(Encoding.ASCII.GetBytes(ScheduleDeliveryTime)));
            pdu.AddRange(SmppStringUtil.ArrayCopyWithNull(Encoding.ASCII.GetBytes(ValidityPeriod)));
            pdu.Add((byte)RegisteredDelivery);

            if (ReplaceIfPresentFlag == true)
            {
                pdu.Add((byte)0x01);
            }
            else
            {
                pdu.Add((byte)0x00);
            }

            pdu.Add((byte)DataCoding);
            pdu.Add(SmDefaultMessageId);
            _SmLength = PduUtil.InsertShortMessage(pdu, ShortMessage);

            pdu.TrimToSize();

            return(pdu);
        }
Example #27
0
        private void CheckPermission()
        {
            try
            {
                string[]  check   = { Manifest.Permission.WriteExternalStorage, Manifest.Permission.ReadExternalStorage, Manifest.Permission.Internet };
                ArrayList request = new ArrayList();

                foreach (string permission in check)
                {
                    if (CheckSelfPermission(permission) == Permission.Denied)
                    {
                        request.Add(permission);
                    }
                }

                request.TrimToSize();

                if (request.Count == 0)
                {
                    InitLoad();
                }
                else
                {
                    RequestPermissions((string[])request.ToArray(typeof(string)), 0);
                }
            }
            catch (Exception ex)
            {
                ETC.LogError(this, ex.ToString());
                Toast.MakeText(this, Resource.String.Permission_Error, ToastLength.Long).Show();
            }
        }
Example #28
0
    private void removeLayer()
    {
        int index = UnityEngine.Random.Range(0, layerCount.Count);

        layerCount.RemoveAt(index);
        layerCount.TrimToSize();
    }
Example #29
0
        private string[] Tokenise(string escapedText)
        {
            ArrayList tokens = new ArrayList(escapedText.Length);
            string    character;

            for (int characterIndex = 0; characterIndex < escapedText.Length; characterIndex++)
            {
                if (escapedText.Substring(characterIndex, 1) == "{")
                {
                    if (escapedText.Substring(characterIndex + 1, 1) == "}")
                    {
                        character      = escapedText.Substring(characterIndex, 3);
                        characterIndex = characterIndex + 2;
                    }
                    else
                    {
                        int endIndex = escapedText.IndexOf("}", characterIndex);
                        character      = escapedText.Substring(characterIndex, endIndex - characterIndex + 1);
                        characterIndex = endIndex;
                    }
                }
                else
                {
                    character = escapedText.Substring(characterIndex, 1);
                }

                tokens.Add(character);
            }

            tokens.TrimToSize();
            return((string[])tokens.ToArray(typeof(string)));
        }
Example #30
0
        public static void Questao1()
        {
            /*1 – Faça um programa que leia n números inteiros e os   armazene em um ArrayList.
             * Calcule a soma e a média     aritmética (use o comando FOR e depois o FOREACH).*/
            Console.Clear();

            ArrayList AL   = new ArrayList();
            double    soma = 0;
            int       num  = 0;

            Console.WriteLine("QUESTÃO 1");
            Console.Write("Quantos números inteiros deseja inserir? \n=> ");
            num = int.Parse(Console.ReadLine());
            Console.WriteLine("Insira os números:");

            for (int i = 0; i < num; i++)
            {
                Console.Write("=> ");
                AL.Add(int.Parse(Console.ReadLine()));
            }
            AL.TrimToSize();
            foreach (int n in AL)
            {
                soma += n;
            }

            Console.WriteLine("Soma = {0}", soma);
            Console.WriteLine("Média = {0}", soma / AL.Count);

            Console.WriteLine("Tecle qualquer coisa para voltar ao menu...");
            Console.ReadKey();
            Console.Clear();
        }
Example #31
0
    protected static string[] listItemCollectionToStringArray(ListItemCollection items)
    {
        ArrayList arrayList = new ArrayList(items.Count);

        foreach (ListItem listItem in items)
        {
            if (listItem.Selected == true)
                arrayList.Add(listItem.Text);
        }

        arrayList.TrimToSize();

        return (string[])arrayList.ToArray(typeof(string));
    }
Example #32
0
        public void TestTrimToSizeBasic()
        {
            //--------------------------------------------------------------------------
            // Variable definitions.
            //--------------------------------------------------------------------------
            ArrayList arrList = null;

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

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

            //
            // []  Verify TrimToSize.
            //
            // Set capacity greater than the size of the ArrayList.
            arrList.Capacity = 2 * arrList.Count;
            Assert.True(arrList.Capacity > arrList.Count);

            // Verify TrimToSize
            arrList.TrimToSize();
            Assert.Equal(arrList.Count, arrList.Capacity);
        }
Example #33
0
 public ArrayList GetArray()
 {
     ArrayList l = new ArrayList(kSize);
     for (int i = 0; i < kSize; i++)
     {
         ArrayList lst = (ArrayList)(activeAlloc[i]);
         if (lst.Count > 0)
         {
             for (int j = 0; j < lst.Count; j++)
             {
                 AddressIndex logentry = (AddressIndex)(lst[j]);
                 l.Add( logentry.index );
             }
         }
     }
     l.TrimToSize();
     return l;
 }
Example #34
0
        static void Main(string[] args)
        {
            ArrayList arr = new ArrayList();
            //выделяет память на 4 элемента, по мере необходимости добавляет ещё на 4
            arr.Add(10);
            arr.Add(2);
            arr.Add(9);
            arr.Add(-2);
            arr.Add(15);
            arr.Add(8);
              //  arr.Add("Vasya");
            arr.Sort();       //Vasya не можем сравнить для сортировки с числами
            arr.TrimToSize();   //устанавливает нужную ёмкость
            Console.WriteLine("Ёмкость: "+arr.Capacity+ "; количество элементов: "+arr.Count);

            foreach (object item in arr)
                Console.Write(item + " ");

            int x = 5;
            arr[0] = x;
            // x = arr[0];      //так нельзя
            x = (int)arr[1];

            Console.WriteLine("\nx = arr[1] => "+x);
            foreach (object item in arr)
                Console.Write(item + " ");

            Console.WriteLine("\n>>>>>>>>>>>>>");

            SortedList slist = new SortedList();
            slist.Add(2, 200);
            slist.Add(1, 300);
            foreach (var item in slist.GetKeyList())
                Console.WriteLine(item);

            Console.ReadKey();
        }
    private void GetLicenseInformations()
    {
        string binDirectory = HttpRuntime.BinDirectory;
        string[] licSearchResult = Directory.GetFiles(binDirectory, "*.lic", SearchOption.TopDirectoryOnly);

        try
        {
            ArrayList al = new ArrayList();
            foreach (string lic in licSearchResult)
            {
                StreamReader sr = null;
                XmlDocument xdoc = new XmlDocument();
                LicenseDescriptor ld = null;
                try
                {
                    sr = new StreamReader(lic, Encoding.UTF8);
                    xdoc.LoadXml(sr.ReadToEnd());
                    ld = new LicenseDescriptor(xdoc);
                    al.Add(ld);
                }
                finally
                {
                    if (sr != null)
                    {
                        sr.Close();
                    }
                    sr = null;
                }
            }
            al.TrimToSize();
            WebUtility.WriteAjaxResult(true, "m55", (LicenseDescriptor[])al.ToArray(typeof(LicenseDescriptor)));
        }
        catch (Exception E)
        {
            WebUtility.WriteAjaxError(E.Message, E);
        }
    }
Example #36
0
 private void CompareObjects(ArrayList good, ArrayList bad, Hashtable hsh1)
 {
     DoIListTests(good, bad, hsh1);
     good.Clear();
     for(int i=0; i<100; i++)
         good.Add(i);
     if(fVerbose)
         Console.WriteLine("CopyTo()");
     Int32[] iArr1 = null;
     Int32[] iArr2 = null;
     iArr1 = new Int32[100];
     iArr2 = new Int32[100];
     good.CopyTo(iArr1);
     bad.CopyTo(iArr2);
     for(int i=0; i<100; i++)
     {
         if(iArr1[i] != iArr2[i])
             hsh1["CopyTo"] = "()";
     }
     iArr1 = new Int32[100];
     iArr2 = new Int32[100];
     good.CopyTo(0, iArr1, 0, 100);
     try
     {
         bad.CopyTo(0, iArr2, 0, 100);
         for(int i=0; i<100; i++)
         {
             if(iArr1[i] != iArr2[i])
                 hsh1["CopyTo"] = "()";
         }
     }
     catch
     {
         hsh1["CopyTo"] = "(Int32, Array, Int32, Int32)";
     }
     iArr1 = new Int32[200];
     iArr2 = new Int32[200];
     for(int i=0; i<200; i++)
     {
         iArr1[i]=50;
         iArr2[i]=50;
     }
     good.CopyTo(50, iArr1, 100, 20);
     try
     {
         bad.CopyTo(50, iArr2, 100, 20);
         for(int i=0; i<200; i++)
         {
             if(iArr1[i] != iArr2[i])
                 hsh1["CopyTo"] = "(Array, Int32, Int32)";
         }
     }
     catch
     {
         hsh1["CopyTo"] = "(Int32, Array, Int32, Int32)";
     }
     if(fVerbose)
         Console.WriteLine("Clone()");
     ArrayList alstClone = (ArrayList)bad.Clone();
     if(alstClone.Count != bad.Count)
         hsh1["Clone"] = "Count";
     for(int i=0; i<bad.Count; i++)
     {
         if(alstClone[i] != bad[i])
             hsh1["Clone"] = "[]";
     }
     if(fVerbose)
         Console.WriteLine("GetEnumerator()");
     IEnumerator ienm1 = null;
     IEnumerator ienm2 = null;
     ienm1 = good.GetEnumerator(0, 100);
     try
     {
         ienm2 = bad.GetEnumerator(0, 100);
         DoIEnumerableTest(ienm1, ienm2, hsh1, false);
     }
     catch
     {
         hsh1["GetEnumerator"] = "(Int32, Int32)";
     }
     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))
             {
                 if(good.IndexOf(good[i], i+1) != bad.IndexOf(good[i], i+1))
                 {
                     Console.WriteLine("3" + good.IndexOf(good[i], i+1) + " " + bad.IndexOf(good[i], i+1));
                     hsh1["IndexOf"] = "(Object, Int32)";
                 }
             }			
         }
         try
         {
             bad.IndexOf(1, -1);
         }
         catch(ArgumentException)
         {
         }
         catch(Exception ex)
         {
             hsh1["IndexOf"] = ex;
         }
         try
         {
             bad.IndexOf(1, bad.Count);
         }
         catch(ArgumentException)
         {
         }
         catch(Exception ex)
         {
             hsh1["IndexOf"] = ex;
         }
         for(int i=0; i<good.Count; i++)
         {
             if(good.IndexOf(good[i], 0, good.Count-1) != bad.IndexOf(good[i], 0, good.Count-1))
             {
                 hsh1["IndexOf"] = "(Object, Int32, Int32)";
             }
             if(good.IndexOf(good[i], i, good.Count-i) != bad.IndexOf(good[i], i, good.Count-i))
             {
                 hsh1["IndexOf"] = "(Object, Int32)";
             }
             if(good.IndexOf(good[i], i, 0) != bad.IndexOf(good[i], i, 0))
             {
                 hsh1["IndexOf"] = "(Object, Int32)";
             }
             if(i<(good.Count-1))
             {
                 if(good.IndexOf(good[i], i+1, good.Count-(i+1)) != bad.IndexOf(good[i], i+1, good.Count-(i+1)))
                 {
                     hsh1["IndexOf"] = "(Object, Int32)";
                 }
             }
         }
         try
         {
             bad.IndexOf(1, 0, -1);
         }
         catch(ArgumentException)
         {
         }
         catch(Exception ex)
         {
             hsh1["IndexOf"] = ex;
         }
         try
         {
             bad.IndexOf(1, 0, bad.Count);
         }
         catch(ArgumentException)
         {
         }
         catch(Exception ex)
         {
             hsh1["IndexOf"] = ex;
         }
         try
         {
             bad.IndexOf(1, bad.Count-1, bad.Count-2);
         }
         catch(ArgumentException)
         {
         }
         catch(Exception ex)
         {
             hsh1["IndexOf"] = ex;
         }
         if(fVerbose)
             Console.WriteLine("LastIndexOf(), " + good.Count + " " + bad.Count);
         for(int i=0; i<good.Count; i++)
         {
             if(good.LastIndexOf(good[i]) != bad.LastIndexOf(good[i]))
             {
                 hsh1["LastIndexOf"] = "(Object)";
             }
             if(good.LastIndexOf(i+1000) != bad.LastIndexOf(i+1000))
             {
                 hsh1["LastIndexOf"] = "(Object)";
             }
         }
         try
         {
             bad.LastIndexOf(null);
         }
         catch(ArgumentException)
         {
         }
         catch(Exception ex)
         {
             hsh1["LastIndexOf"] = ex;
         }
         if(fVerbose)
             Console.WriteLine("LastIndexOf(Object, Int32)");
         for(int i=0; i<good.Count; i++)
         {
             if(good.LastIndexOf(good[i], good.Count-1) != bad.LastIndexOf(good[i], good.Count-1))
             {
                 hsh1["LastIndexOf"] = "(Object, Int32)";
             }
             if(good.LastIndexOf(good[i], 0) != bad.LastIndexOf(good[i], 0))
             {
                 hsh1["LastIndexOf"] = "(Object, Int32)";
             }
             if(good.LastIndexOf(good[i], i) != bad.LastIndexOf(good[i], i))
             {
                 hsh1["LastIndexOf"] = "(Object, Int32)";
             }
             if(i<(good.Count-1))
             {
                 if(good.LastIndexOf(good[i], i+1) != bad.LastIndexOf(good[i], i+1))
                 {
                     hsh1["LastIndexOf"] = "(Object, Int32)";
                 }
             }			
         }
         try
         {
             bad.LastIndexOf(1, -1);
         }
         catch(ArgumentException)
         {
         }
         catch(Exception ex)
         {
             hsh1["LastIndexOf"] = ex;
         }
         try
         {
             bad.LastIndexOf(1, bad.Count);
         }
         catch(ArgumentException)
         {
         }
         catch(Exception ex)
         {
             hsh1["LastIndexOf"] = ex;
         }
         for(int i=0; i<good.Count; i++)
         {
             if(good.LastIndexOf(good[i], good.Count-1, 0) != bad.LastIndexOf(good[i], good.Count-1, 0))
             {
                 hsh1["LastIndexOf"] = "(Object, Int32, Int32)";
             }
             if(good.LastIndexOf(good[i], good.Count-1, i) != bad.LastIndexOf(good[i], good.Count-1, i))
             {
                 hsh1["LastIndexOf"] = "(Object, Int32)";
             }
             if(good.LastIndexOf(good[i], i, i) != bad.LastIndexOf(good[i], i, i))
             {
                 hsh1["LastIndexOf"] = "(Object, Int32)";
             }
             if(i<(good.Count-1))
             {
                 if(good.LastIndexOf(good[i], good.Count-1, i+1) != bad.LastIndexOf(good[i], good.Count-1, i+1))
                 {
                     hsh1["LastIndexOf"] = "(Object, Int32)";
                 }
             }
         }
         try
         {
             bad.LastIndexOf(1, 1, -1);
         }
         catch(ArgumentException)
         {
         }
         catch(Exception ex)
         {
             hsh1["LastIndexOf"] = ex;
         }
         try
         {
             bad.LastIndexOf(1, bad.Count-2, bad.Count-1);
         }
         catch(ArgumentException)
         {
         }
         catch(Exception ex)
         {
             hsh1["LastIndexOf"] = ex;
         }
     }
     if(fVerbose)
         Console.WriteLine("ReadOnly()");
     ArrayList alst3 = ArrayList.ReadOnly(bad);
     if(!alst3.IsReadOnly)
         hsh1["ReadOnly"] = "Not";
     IList ilst1 = ArrayList.ReadOnly((IList)bad);
     if(!ilst1.IsReadOnly)
         hsh1["ReadOnly"] = "Not";
     if(fVerbose)
         Console.WriteLine("Synchronized()");
     alst3 = ArrayList.Synchronized(bad);
     if(!alst3.IsSynchronized)
         hsh1["Synchronized"] = "Not";
     ilst1 = ArrayList.Synchronized((IList)bad);
     if(!ilst1.IsSynchronized)
         hsh1["Synchronized"] = "Not";
     if(good.Count == bad.Count)
     {
         if(fVerbose)
             Console.WriteLine("ToArray()");
         Object[] oArr1 = good.ToArray();
         Object[] oArr2 = bad.ToArray();
         for(int i=0; i<good.Count; i++)
         {
             if((Int32)oArr1[i] != (Int32)oArr2[i])
                 hsh1["ToArray"] = "()";
         }
         iArr1 = (Int32[])good.ToArray(typeof(Int32));
         iArr2 = (Int32[])bad.ToArray(typeof(Int32));
         for(int i=0; i<good.Count; i++)
         {
             if(iArr1[i] != iArr2[i])
                 hsh1["ToArray"] = "(Type)";
         }
     }
     if(fVerbose)
         Console.WriteLine("Capacity()");
     if(good.Capacity != bad.Capacity)
     {
         hsh1["Capacity"] = "get";
     }
     if(!hsh1.ContainsKey("IsReadOnly"))
     {
         good.Clear();
         for(int i=100; i>0; i--)
             good.Add(i);
         if(fVerbose)
             Console.WriteLine("Sort() & BinarySearch()");
         bad.Sort();
         for(int i=0; i<bad.Count-1; i++)
         {
             if((Int32)bad[i] > (Int32)bad[i+1])
                 hsh1["Sort"] = "()";
         }			
         for(int i=0; i<bad.Count; i++)
         {
             if(bad.BinarySearch(bad[i]) != i)
                 hsh1["BinarySearch"] = "(Object)";
         }
         bad.Reverse();
         if(bad.Count>0)
         {
             for(int i=0; i<99; i++)
             {
                 if((Int32)bad[i] < (Int32)bad[i+1])
                     hsh1["Reverse"] = "()";
             }
             good.Clear();
             for(int i=100; i>0; i--)
                 good.Add(i.ToString());
         }
         good.Clear();
         for(int i=90; i>64; i--)
             good.Add(((Char)i).ToString());
         try
         {
             bad.Sort(new CaseInsensitiveComparer());
             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)
         {
         }
         catch(Exception)
         {
             hsh1["Sort"] = "Copy_ExceptionType";
         }
         try
         {
             bad.Reverse();
             hsh1["Reverse"] = "Copy";
         }
         catch(NotSupportedException)
         {
         }
         catch(Exception ex)
         {
             hsh1["Reverse"] = "Copy_ExceptionType, " + ex.GetType().Name;
         }
         try
         {
             bad.Sort(new CaseInsensitiveComparer());
             hsh1["Sort"] = "Copy - Icomparer";
         }
         catch(NotSupportedException)
         {
         }
         catch(Exception)
         {
             hsh1["Sort"] = "Copy_ExceptionType";
         }
         try
         {
             bad.Sort(0, 0, new CaseInsensitiveComparer());
             hsh1["Sort"] = "Copy - Int32, Int32, IComparer";
         }
         catch(NotSupportedException)
         {
         }
         catch(Exception)
         {
             hsh1["Sort"] = "Copy_ExceptionType";
         }
         try
         {
             for(int i=0; i<bad.Count; i++)
             {
                 if(bad.BinarySearch(bad[i]) != i)
                     hsh1["BinarySearch"] = "(Object)";
             }
             hsh1["BinarySearch"] = "(Object)";
         }
         catch(NotSupportedException)
         {
         }
         catch(Exception ex)
         {
             hsh1["BinarySearch"] = ex.GetType().Name;
         }
         try
         {
             for(int i=0; i<bad.Count; i++)
             {
                 if(bad.BinarySearch(bad[i], new CaseInsensitiveComparer()) != i)
                     hsh1["BinarySearch"] = "(Object)";
             }
             hsh1["BinarySearch"] = "Exception not thrown, (Object, IComparer)";
         }
         catch(NotSupportedException)
         {
         }
         catch(Exception ex)
         {
             hsh1["BinarySearch"] = ex.GetType().Name;
         }
         try
         {
             for(int i=0; i<bad.Count; i++)
             {
                 if(bad.BinarySearch(0, bad.Count, bad[i], new CaseInsensitiveComparer()) != i)
                     hsh1["BinarySearch"] = "(Object)";
             }
             hsh1["BinarySearch"] = "Exception not thrown, (Object, IComparer)";
         }
         catch(NotSupportedException)
         {
         }
         catch(Exception ex)
         {
             hsh1["BinarySearch"] = ex.GetType().Name;
         }
         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);
             hsh1["Sort"] = "Copy - Int32, Int32, IComparer";
         }
         catch(NotSupportedException)
         {
         }
         catch(Exception)
         {
             hsh1["Sort"] = "Copy_ExceptionType";
         }
     }
     if(!hsh1.ContainsKey("IsReadOnly") && !hsh1.ContainsKey("Fixed"))
     {
         good.Clear();
         for(int i=0; i<100; i++)
             good.Add(i);
         if(fVerbose)
             Console.WriteLine("InsertRange()");
         Queue que = new Queue();
         for(int i=0; i<100; i++)
             que.Enqueue(i+5000);
         bad.InsertRange(0, que);
         for(int i=0; i<100; i++)
         {
             if((Int32)bad[i] != i + 5000)
             {
                 hsh1["InsertRange"] = i;
             }
         }
         if(fVerbose)
             Console.WriteLine("AddRange()");
         que = new Queue();
         for(int i=0; i<100; i++)
             que.Enqueue(i+2222);
         bad.AddRange(que);
         for(int i=bad.Count-100; i<bad.Count; i++)
         {
             if((Int32)bad[i] != (i-(bad.Count-100)) + 2222)
             {
                 hsh1["AddRange"] = i + " " + (Int32)bad[i];
             }
         }
         if(fVerbose)
             Console.WriteLine("RemoveRange()");
         bad.RemoveRange(0, que.Count);
         for(int i=0; i<100; i++)
         {
             if((Int32)bad[i] != i)
             {
                 hsh1["RemoveRange"] = i + " " + (Int32)bad[i];
             }
         }
         try
         {
             bad.Capacity = bad.Capacity*2;
         }
         catch(Exception ex)
         {
             hsh1["Capacity"] = ex.GetType().Name;
         }
         try
         {
             bad.Capacity = -1;
             hsh1["Capacity"] = "No_Exception_Thrown, -1";
         }
         catch(ArgumentException)
         {
         }
         catch(Exception ex)
         {
             hsh1["Capacity"] = ex.GetType().Name;
         }
         Int32 iMakeSureThisDoesNotCause = 0;
         while(bad.Capacity == bad.Count)
         {
             if(iMakeSureThisDoesNotCause++>100)
                 break;
             bad.Add(bad.Count);
         }
         if(iMakeSureThisDoesNotCause>100)
             hsh1["TrimToSize"] = "Monekeyed, " + bad.Count + " " + bad.Capacity;
         try
         {
             bad.TrimToSize();
             if(bad.Capacity != bad.Count)
             {
                 hsh1["TrimToSize"] = "Problems baby";
             }
         }
         catch(Exception ex)
         {
             hsh1["TrimToSize"] = ex.GetType().Name;
         }
     }
     else
     {
         Queue que = new Queue();
         for(int i=0; i<100; i++)
             que.Enqueue(i+5000);
         try
         {
             bad.AddRange(que);
             hsh1["AddRange"] = "Copy";
         }
         catch(NotSupportedException)
         {
         }
         catch(Exception)
         {
             hsh1["AddRange"] = "Copy_ExceptionType";
         }
         try
         {
             bad.InsertRange(0, que);
             hsh1["InsertRange"] = "Copy";
         }
         catch(NotSupportedException)
         {
         }
         catch(Exception)
         {
             hsh1["InsertRange"] = "Copy_ExceptionType";
         }
         good.Clear();
         for(int i=0; i<10; i++)
             good.Add(i);
         try
         {
             bad.RemoveRange(0, 10);
             hsh1["RemoveRange"] = "Copy";
         }
         catch(NotSupportedException)
         {
         }
         catch(Exception ex)
         {
             hsh1["RemoveRange"] = "Copy_ExceptionType, " + ex.GetType().Name;
         }
         try
         {
             bad.Capacity = bad.Capacity*2;
             hsh1["Capacity"] = "No_Exception_Thrown, bad.Capacity*2";
         }
         catch(NotSupportedException)
         {
         }
         catch(Exception ex)
         {
             hsh1["Capacity"] = ex.GetType().Name;
         }
         try
         {
             bad.TrimToSize();
             hsh1["TrimToSize"] = "No_Exception_Thrown";
         }
         catch(NotSupportedException)
         {
         }
         catch(Exception ex)
         {
             hsh1["TrimToSize"] = ex.GetType().Name;
         }
     }
 }
Example #37
0
            public ArrayList GetArrayAddressSorted(ref int maxlogindex)
            {
                ArrayList l = new ArrayList(kSize);
                maxlogindex = -1;
                for (int i = 0; i < kSize; i++)
                {
                    ArrayList lst = (ArrayList)(activeAlloc[i]);
                    if (lst.Count > 0)
                    {
                        for (int j = 0; j < lst.Count; j++)
                        {
                            AddressIndex logentry = (AddressIndex)(lst[j]);
                            l.Add(logentry);
                            maxlogindex = maxlogindex >= logentry.index ? maxlogindex : logentry.index;
                        }
                    }
                }

                l.TrimToSize();
                l.Sort(new CompareAddresses());

                ArrayList ll = new ArrayList(l.Count);
                for (int i = 0; i < l.Count; i++)
                {
                    AddressIndex logentry = (AddressIndex)(l[i]);
                    ll.Add(logentry.index);
                }

                return ll;
            }
Example #38
0
    private void CompareObjects(ArrayList good, ArrayList bad, Hashtable hsh1)
    {
        //IList, this includes ICollection tests as well!!
        DoIListTests(good, bad, hsh1);

        //we will now test ArrayList specific methods
        good.Clear();
        for (int i = 0; i < 100; i++)
            good.Add(i);

        //AL's CopyTo methods
        int[] iArr1 = null;
        int[] iArr2 = null;
        iArr1 = new int[100];
        iArr2 = new int[100];
        good.CopyTo(iArr1);
        bad.CopyTo(iArr2);
        for (int i = 0; i < 100; i++)
        {
            if (iArr1[i] != iArr2[i])
                hsh1["CopyTo"] = "()";
        }

        iArr1 = new int[100];
        iArr2 = new int[100];
        good.CopyTo(0, iArr1, 0, 100);
        try
        {
            bad.CopyTo(0, iArr2, 0, 100);
            for (int i = 0; i < 100; i++)
            {
                if (iArr1[i] != iArr2[i])
                    hsh1["CopyTo"] = "()";
            }
        }
        catch
        {
            hsh1["CopyTo"] = "(int, Array, int, int)";
        }

        iArr1 = new int[200];
        iArr2 = new int[200];
        for (int i = 0; i < 200; i++)
        {
            iArr1[i] = 50;
            iArr2[i] = 50;
        }

        good.CopyTo(50, iArr1, 100, 20);
        try
        {
            bad.CopyTo(50, iArr2, 100, 20);
            for (int i = 0; i < 200; i++)
            {
                if (iArr1[i] != iArr2[i])
                    hsh1["CopyTo"] = "(Array, int, int)";
            }
        }
        catch
        {
            hsh1["CopyTo"] = "(int, Array, int, int)";
        }

        //Clone()
        ArrayList alstClone = (ArrayList)bad.Clone();
        //lets make sure that the clone is what it says it is
        if (alstClone.Count != bad.Count)
            hsh1["Clone"] = "Count";
        for (int i = 0; i < bad.Count; i++)
        {
            if (alstClone[i] != bad[i])
                hsh1["Clone"] = "[]";
        }

        //GerEnumerator()
        IEnumerator ienm1 = null;
        IEnumerator ienm2 = null;

        ienm1 = good.GetEnumerator(0, 100);
        try
        {
            ienm2 = bad.GetEnumerator(0, 100);
            DoIEnumerableTest(ienm1, ienm2, good, bad, hsh1, false);
        }
        catch
        {
            hsh1["GetEnumerator"] = "(int, int)";
        }

        ienm1 = good.GetEnumerator(50, 50);
        try
        {
            ienm2 = bad.GetEnumerator(50, 50);
            DoIEnumerableTest(ienm1, ienm2, good, bad, hsh1, false);
        }
        catch
        {
            hsh1["GetEnumerator"] = "(int, int)";
        }

        try
        {
            bad.GetEnumerator(50, 150);
            hsh1["GetEnumerator"] = "(int, int)";
        }
        catch (Exception)
        {
        }

        ienm1 = good.GetEnumerator(0, 100);
        try
        {
            ienm2 = bad.GetEnumerator(0, 100);
            good.RemoveAt(0);
            DoIEnumerableTest(ienm1, ienm2, good, bad, hsh1, true);
        }
        catch
        {
            hsh1["GetEnumerator"] = "(int, int)";
        }

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

        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"] = "(int, int)";
        }

        //IndexOf(Object, int)

        if (bad.Count > 0)
        {
            for (int i = 0; i < good.Count; i++)
            {
                if (good.IndexOf(good[i], 0) != bad.IndexOf(good[i], 0))
                {
                    hsh1["IndexOf"] = "(Object, int)";
                }
                if (good.IndexOf(good[i], i) != bad.IndexOf(good[i], i))
                {
                    hsh1["IndexOf"] = "(Object, int)";
                }
                if (i < (good.Count - 1))
                {
                    if (good.IndexOf(good[i], i + 1) != bad.IndexOf(good[i], i + 1))
                    {
                        hsh1["IndexOf"] = "(Object, int)";
                    }
                }
            }

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

            try
            {
                bad.IndexOf(1, bad.Count);
            }
            catch (ArgumentException)
            {
            }
            catch (Exception ex)
            {
                hsh1["IndexOf"] = ex;
            }

            // IndexOf(Object, int, int)
            // The semantics of this method has changed, the 3rd parameter now refers to count instead of length
            for (int i = 0; i < good.Count; i++)
            {
                if (good.IndexOf(good[i], 0, good.Count - 1) != bad.IndexOf(good[i], 0, good.Count - 1))
                {
                    hsh1["IndexOf"] = "(Object, int, int)";
                }
                if (good.IndexOf(good[i], i, good.Count - i) != bad.IndexOf(good[i], i, good.Count - i))
                {
                    hsh1["IndexOf"] = "(Object, int)";
                }
                if (good.IndexOf(good[i], i, 0) != bad.IndexOf(good[i], i, 0))
                {
                    hsh1["IndexOf"] = "(Object, int)";
                }
                if (i < (good.Count - 1))
                {
                    if (good.IndexOf(good[i], i + 1, good.Count - (i + 1)) != bad.IndexOf(good[i], i + 1, good.Count - (i + 1)))
                    {
                        hsh1["IndexOf"] = "(Object, int)";
                    }
                }
            }

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

            try
            {
                bad.IndexOf(1, 0, bad.Count);
            }
            catch (ArgumentException)
            {
            }
            catch (Exception ex)
            {
                hsh1["IndexOf"] = ex;
            }

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

            //LastIndexOf(Object)
            for (int i = 0; i < good.Count; i++)
            {
                if (good.LastIndexOf(good[i]) != bad.LastIndexOf(good[i]))
                {
                    hsh1["LastIndexOf"] = "(Object)";
                }
                if (good.LastIndexOf(i + 1000) != bad.LastIndexOf(i + 1000))
                {
                    hsh1["LastIndexOf"] = "(Object)";
                }
            }

            try
            {
                bad.LastIndexOf(null);
            }
            catch (ArgumentException)
            {
            }
            catch (Exception ex)
            {
                hsh1["LastIndexOf"] = ex;
            }

            //LastIndexOf(Object, int)
            for (int i = 0; i < good.Count; i++)
            {
                if (good.LastIndexOf(good[i], good.Count - 1) != bad.LastIndexOf(good[i], good.Count - 1))
                {
                    hsh1["LastIndexOf"] = "(Object, int)";
                }
                if (good.LastIndexOf(good[i], 0) != bad.LastIndexOf(good[i], 0))
                {
                    hsh1["LastIndexOf"] = "(Object, int)";
                }
                if (good.LastIndexOf(good[i], i) != bad.LastIndexOf(good[i], i))
                {
                    hsh1["LastIndexOf"] = "(Object, int)";
                }
                if (i < (good.Count - 1))
                {
                    if (good.LastIndexOf(good[i], i + 1) != bad.LastIndexOf(good[i], i + 1))
                    {
                        hsh1["LastIndexOf"] = "(Object, int)";
                    }
                }
            }

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

            try
            {
                bad.LastIndexOf(1, bad.Count);
            }
            catch (ArgumentException)
            {
            }
            catch (Exception ex)
            {
                hsh1["LastIndexOf"] = ex;
            }

            //LastIndexOf(Object, int, int)
            for (int i = 0; i < good.Count; i++)
            {
                if (good.LastIndexOf(good[i], good.Count - 1, 0) != bad.LastIndexOf(good[i], good.Count - 1, 0))
                {
                    hsh1["LastIndexOf"] = "(Object, int, int)";
                }
                if (good.LastIndexOf(good[i], good.Count - 1, i) != bad.LastIndexOf(good[i], good.Count - 1, i))
                {
                    hsh1["LastIndexOf"] = "(Object, int)";
                }
                if (good.LastIndexOf(good[i], i, i) != bad.LastIndexOf(good[i], i, i))
                {
                    hsh1["LastIndexOf"] = "(Object, int)";
                }
                if (i < (good.Count - 1))
                {
                    if (good.LastIndexOf(good[i], good.Count - 1, i + 1) != bad.LastIndexOf(good[i], good.Count - 1, i + 1))
                    {
                        hsh1["LastIndexOf"] = "(Object, int)";
                    }
                }
            }

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

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

        //ReadOnly()
        ArrayList alst3 = ArrayList.ReadOnly(bad);
        if (!alst3.IsReadOnly)
            hsh1["ReadOnly"] = "Not";

        IList ilst1 = ArrayList.ReadOnly((IList)bad);
        if (!ilst1.IsReadOnly)
            hsh1["ReadOnly"] = "Not";

        //Synchronized()
        alst3 = ArrayList.Synchronized(bad);
        if (!alst3.IsSynchronized)
            hsh1["Synchronized"] = "Not";

        ilst1 = ArrayList.Synchronized((IList)bad);
        if (!ilst1.IsSynchronized)
            hsh1["Synchronized"] = "Not";

        //ToArray()
        if (good.Count == bad.Count)
        {
            object[] oArr1 = good.ToArray();
            object[] oArr2 = bad.ToArray();
            for (int i = 0; i < good.Count; i++)
            {
                if ((int)oArr1[i] != (int)oArr2[i])
                    hsh1["ToArray"] = "()";
            }

            //ToArray(type)
            iArr1 = (int[])good.ToArray(typeof(int));
            iArr2 = (int[])bad.ToArray(typeof(int));
            for (int i = 0; i < good.Count; i++)
            {
                if (iArr1[i] != iArr2[i])
                    hsh1["ToArray"] = "(Type)";
            }
        }

        //Capacity - get
        if (good.Capacity != bad.Capacity)
        {
            hsh1["Capacity"] = "get";
        }

        //Fixed size methods
        if (!hsh1.ContainsKey("IsReadOnly"))
        {
            good.Clear();
            for (int i = 100; i > 0; i--)
                good.Add(i);
            //Sort() & BinarySearch(Object)
            bad.Sort();
            for (int i = 0; i < bad.Count - 1; i++)
            {
                if ((int)bad[i] > (int)bad[i + 1])
                    hsh1["Sort"] = "()";
            }

            for (int i = 0; i < bad.Count; i++)
            {
                if (bad.BinarySearch(bad[i]) != i)
                    hsh1["BinarySearch"] = "(Object)";
            }

            //Reverse()
            bad.Reverse();
            if (bad.Count > 0)
            {
                for (int i = 0; i < 99; i++)
                {
                    if ((int)bad[i] < (int)bad[i + 1])
                        hsh1["Reverse"] = "()";
                }

                good.Clear();
                for (int i = 100; i > 0; i--)
                    good.Add(i.ToString());
            }

            good.Clear();
            for (int i = 90; i > 64; i--)
                good.Add(((Char)i).ToString());

            try
            {
                bad.Sort(new CaseInsensitiveComparer());
                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"] = "(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";
            }

            try
            {
                bad.Reverse();
                hsh1["Reverse"] = "Copy";
            }
            catch (NotSupportedException)
            {
            }
            catch (Exception ex)
            {
                hsh1["Reverse"] = "Copy_ExceptionType, " + ex.GetType().Name;
            }

            try
            {
                bad.Sort(new CaseInsensitiveComparer());
                hsh1["Sort"] = "Copy - Icomparer";
            }
            catch (NotSupportedException)
            {
            }
            catch (Exception)
            {
                hsh1["Sort"] = "Copy_ExceptionType";
            }

            try
            {
                bad.Sort(0, 0, new CaseInsensitiveComparer());
                hsh1["Sort"] = "Copy - int, int, IComparer";
            }
            catch (NotSupportedException)
            {
            }
            catch (Exception)
            {
                hsh1["Sort"] = "Copy_ExceptionType";
            }

            //BinarySearch
            try
            {
                for (int i = 0; i < bad.Count; i++)
                {
                    if (bad.BinarySearch(bad[i]) != i)
                        hsh1["BinarySearch"] = "(Object)";
                }
                hsh1["BinarySearch"] = "(Object)";
            }
            catch (NotSupportedException)
            {
            }
            catch (Exception ex)
            {
                hsh1["BinarySearch"] = ex.GetType().Name;
            }

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

                hsh1["BinarySearch"] = "Exception not thrown, (Object, IComparer)";
            }
            catch (NotSupportedException)
            {
            }
            catch (Exception ex)
            {
                hsh1["BinarySearch"] = ex.GetType().Name;
            }

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

                hsh1["BinarySearch"] = "Exception not thrown, (Object, IComparer)";
            }
            catch (NotSupportedException)
            {
            }
            catch (Exception ex)
            {
                hsh1["BinarySearch"] = ex.GetType().Name;
            }

            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);
                hsh1["Sort"] = "Copy - int, int, IComparer";
            }
            catch (NotSupportedException)
            {
            }
            catch (Exception)
            {
                hsh1["Sort"] = "Copy_ExceptionType";
            }
        }

        //Modifiable methods
        if (!hsh1.ContainsKey("IsReadOnly") && !hsh1.ContainsKey("Fixed"))
        {
            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);
            bad.InsertRange(0, que);
            for (int i = 0; i < 100; i++)
            {
                if ((int)bad[i] != i + 5000)
                {
                    hsh1["InsertRange"] = i;
                }
            }

            //AddRange()
            que = new Queue();
            for (int i = 0; i < 100; i++)
                que.Enqueue(i + 2222);
            bad.AddRange(que);
            for (int i = bad.Count - 100; i < bad.Count; i++)
            {
                if ((int)bad[i] != (i - (bad.Count - 100)) + 2222)
                {
                    hsh1["AddRange"] = i + " " + (int)bad[i];
                }
            }

            bad.RemoveRange(0, que.Count);
            for (int i = 0; i < 100; i++)
            {
                if ((int)bad[i] != i)
                {
                    hsh1["RemoveRange"] = i + " " + (int)bad[i];
                }
            }

            //Capacity
            try
            {
                bad.Capacity = bad.Capacity * 2;
            }
            catch (Exception ex)
            {
                hsh1["Capacity"] = ex.GetType().Name;
            }

            try
            {
                bad.Capacity = -1;
                hsh1["Capacity"] = "No_Exception_Thrown, -1";
            }
            catch (ArgumentException)
            {
            }
            catch (Exception ex)
            {
                hsh1["Capacity"] = ex.GetType().Name;
            }

            int iMakeSureThisDoesNotCause = 0;
            while (bad.Capacity == bad.Count)
            {
                if (iMakeSureThisDoesNotCause++ > 100)
                    break;
                bad.Add(bad.Count);
            }
            if (iMakeSureThisDoesNotCause > 100)
                hsh1["TrimToSize"] = "Monekeyed, " + bad.Count + " " + bad.Capacity;

            //TrimToSize()
            try
            {
                bad.TrimToSize();
                if (bad.Capacity != bad.Count)
                {
                    hsh1["TrimToSize"] = "Problems baby";
                }
            }
            catch (Exception ex)
            {
                hsh1["TrimToSize"] = ex.GetType().Name;
            }
        }
        else
        {
            Queue que = new Queue();
            for (int i = 0; i < 100; i++)
                que.Enqueue(i + 5000);
            try
            {
                bad.AddRange(que);
                hsh1["AddRange"] = "Copy";
            }
            catch (NotSupportedException)
            {
            }
            catch (Exception)
            {
                hsh1["AddRange"] = "Copy_ExceptionType";
            }

            try
            {
                bad.InsertRange(0, que);
                hsh1["InsertRange"] = "Copy";
            }
            catch (NotSupportedException)
            {
            }
            catch (Exception)
            {
                hsh1["InsertRange"] = "Copy_ExceptionType";
            }

            good.Clear();
            for (int i = 0; i < 10; i++)
                good.Add(i);
            try
            {
                bad.RemoveRange(0, 10);
                hsh1["RemoveRange"] = "Copy";
            }
            catch (NotSupportedException)
            {
            }
            catch (Exception ex)
            {
                hsh1["RemoveRange"] = "Copy_ExceptionType, " + ex.GetType().Name;
            }

            try
            {
                bad.Capacity = bad.Capacity * 2;
                hsh1["Capacity"] = "No_Exception_Thrown, bad.Capacity*2";
            }
            catch (NotSupportedException)
            {
            }
            catch (Exception ex)
            {
                hsh1["Capacity"] = ex.GetType().Name;
            }

            try
            {
                bad.TrimToSize();
                hsh1["TrimToSize"] = "No_Exception_Thrown";
            }
            catch (NotSupportedException)
            {
            }
            catch (Exception ex)
            {
                hsh1["TrimToSize"] = ex.GetType().Name;
            }
        }
    }
 public virtual bool runTest()
 {
     int iCountErrors = 0;
     int iCountTestcases = 0;
     Console.Error.WriteLine( strName + ": " + strTest + " runTest started..." );
     ArrayList arrList = null;
     String [] strHeroes =
         {
             "Green Arrow",
             "Atom",
             "Batman",
             "Steel",
             "Superman",
             "Wonder Woman",
             "Hawkman",
             "Flash",
             "Aquaman",
             "Green Lantern",
             "Catwoman",
             "Huntress",
             "Robin",
             "Captain Atom",
             "Wildcat",
             "Nightwing",
             "Ironman",
             "SpiderMan",
             "Black Canary",
             "Thor",
             "Cyborg",
             "Captain America",
     };
     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;
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine( strTest+ "E_10001: Unexpected Exception: " + ex.ToString() );
             ++iCountErrors;
             break;
         }
         ++iCountTestcases;
         Console.Error.WriteLine( "[]  Test ascending TrimToSize" );
         try
         {
             arrList.Capacity =  2 * arrList.Count ;
             if ( arrList.Capacity <= arrList.Count )
             {
                 String strInfo = strTest + " error: ";
                 strInfo = strInfo + "Expected capacity <"+ 2 * arrList.Count + "> ";
                 strInfo = strInfo + "Returned capacity <"+ arrList.Capacity + "> ";
                 Console.WriteLine( strTest+ "E_202: " + strInfo );
                 ++iCountErrors;
                 break;
             }
             arrList.TrimToSize();
             if ( arrList.Capacity != arrList.Count )
             {
                 String strInfo = strTest + " error: ";
                 strInfo = strInfo + "Expected capacity <"+ 2 * arrList.Count + "> ";
                 strInfo = strInfo + "Returned capacity <"+ arrList.Capacity + "> ";
                 Console.WriteLine( strTest+ "E_202: " + strInfo );
                 ++iCountErrors;
                 break;
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine( strTest+ "E_10002: Unexpected Exception: " + ex.ToString() );
             ++iCountErrors;
             break;
         }
     }
     while ( false );
     Console.Error.Write( strName );
     Console.Error.Write( ": " );
     if ( iCountErrors == 0 )
     {
         Console.Error.WriteLine( strTest + " iCountTestcases==" + iCountTestcases + " paSs" );
         return true;
     }
     else
     {
         System.String strFailMsg = null;
         Console.WriteLine( strTest+ strPath );
         Console.WriteLine( strTest+ "FAiL" );
         Console.Error.WriteLine( strTest + " iCountErrors==" + iCountErrors );
         return false;
     }
 }