public void TrimToSize()
 {
     mutex.WaitOne();
     try
     {
         array.TrimToSize();
     }
     finally
     {
         mutex.ReleaseMutex();
     }
 }
Beispiel #2
0
        private void btnTrimToSize_Click(object sender, EventArgs e)
        {
            System.Collections.ArrayList student =
                new System.Collections.ArrayList();
            student.Add("Ryu");
            student.Add("Candy");
            int oldCapacity = student.Capacity;

            student.TrimToSize();

            int newCapacity = student.Capacity;

            string msg = "調整前陣列元素可容納:" + oldCapacity + "個\n";

            msg = msg + "調整後陣列元素可容納:" + newCapacity + "個\n";
            msg = msg + "目前Capacity和Count的內容值是相等";
            MessageBox.Show(msg, "TrimToSize()方法");
        }
Beispiel #3
0
 public void TrimToSize()
 {
     arr.TrimToSize();
 }
Beispiel #4
0
        /// <summary>
        /// 读取配置文件
        /// </summary>
        private void m_mthReadXML()
        {
            XmlTextReader reader    = null;
            int           m_intTemp = 0;

            try
            {
                reader    = new XmlTextReader(m_strConfigFilePath);
                arrStatus = new System.Collections.ArrayList(10);
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element && reader.Name == "LeisureMessage")
                    {
                        arrStatus.Add(reader.GetAttribute("name"));
                        dictLeisureMsg = new Dictionary <string, string>();
                        //读取闲置消息
                        while (reader.Read())
                        {
                            if (reader.NodeType == XmlNodeType.Element)
                            {
                                m_intTemp = int.Parse(reader.GetAttribute("key"));
                                if (m_intTemp > maxKey1)
                                {
                                    maxKey1 = m_intTemp;
                                }
                                dictLeisureMsg.Add(reader.GetAttribute("key"), reader.GetAttribute("value"));
                            }
                            else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "LeisureMessage")
                            {
                                break;
                            }
                        }
                    }

                    if (reader.NodeType == XmlNodeType.Element && reader.Name == "PauseMessage")
                    {
                        arrStatus.Add(reader.GetAttribute("name"));
                        dictPauseMsg = new Dictionary <string, string>();
                        //读取暂停消息
                        while (reader.Read())
                        {
                            if (reader.NodeType == XmlNodeType.Element)
                            {
                                m_intTemp = int.Parse(reader.GetAttribute("key"));
                                if (m_intTemp > maxKey2)
                                {
                                    maxKey2 = m_intTemp;
                                }
                                dictPauseMsg.Add(reader.GetAttribute("key"), reader.GetAttribute("value"));
                            }
                            else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "PauseMessage")
                            {
                                break;
                            }
                        }
                    }
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
                arrStatus.TrimToSize();
            }
        }
Beispiel #5
0
        /// <summary>
        /// پیاده سازی اری لیست
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            System.Collections.ArrayList oList = new System.Collections.ArrayList();

            System.Console.WriteLine("List count: {0}", oList.Count.ToString());
            System.Console.WriteLine("List capacity: {0}", oList.Capacity.ToString());

            System.Console.WriteLine("\n----------\n");

            oList.Add("Ali Reza Alavi");
            oList.Add("Sara Ahmadi");
            oList.Add("Sanaz Samimi");

            foreach (string strCurrent in oList)
            {
                System.Console.WriteLine(strCurrent);
            }

            System.Console.WriteLine("\n----------\n");

            for (int intIndex = 0; intIndex <= oList.Count - 1; intIndex++)
            {
                System.Console.WriteLine(oList[intIndex].ToString());
            }

            System.Console.WriteLine("\n----------\n");

            oList.Sort();
            System.Console.WriteLine("List count: {0}", oList.Count.ToString());
            System.Console.WriteLine("List capacity: {0}", oList.Capacity.ToString());

            System.Console.WriteLine("\n----------\n");

            oList.TrimToSize();

            System.Console.WriteLine("List count: {0}", oList.Count.ToString());
            System.Console.WriteLine("List capacity: {0}", oList.Capacity.ToString());

            System.Console.WriteLine("\n----------\n");

            oList.Clear();

            foreach (string strCurrent in oList)
            {
                System.Console.WriteLine(strCurrent);
            }

            System.Console.WriteLine("\n----------\n");

            oList.Add("Ali Reza Alavi2");
            oList.Add("Sara Ahmadi2");
            oList.Add("Sanaz Samimi2");

            if (oList.Contains("Dariush Tasdighi"))
            {
                System.Console.WriteLine("List contains Dariush Tasdighi");
            }
            else
            {
                System.Console.WriteLine("List does not contain Dariush Tasdighi");
            }

            if (oList.Contains("Sara Ahmadi2"))
            {
                System.Console.WriteLine("List contains Sara Ahmadi");
            }
            else
            {
                System.Console.WriteLine("List does not contain Sara Ahmadi2");
            }

            System.Console.WriteLine("\n----------\n");

            oList.Clear();

            oList.Add("A");
            oList.Add("B");
            oList.Add("C");
            oList.Add("D");
            oList.Add("E");
            oList.Add("F");
            oList.Add("G");
            oList.Add("H");
            oList.Add("I");
            oList.Add("J");
            oList.Add("B");

            oList.Remove("B");
            oList.RemoveAt(1);

            foreach (string strCurrent in oList)
            {
                System.Console.WriteLine(strCurrent);
            }

            System.Console.WriteLine("\n----------\n");

            oList.Reverse();
            oList.Sort();

            foreach (string strCurrent in oList)
            {
                System.Console.WriteLine(strCurrent);
            }

            System.Console.ReadLine();
        }