C#基础【六】集合

            //ArrayList arry = new ArrayList();
            //arry.Add(1);
            //arry.Add(2);
            //arry.Add(3);
            //arry.Add(4);
            //arry.Add(5);
            //for (int i = 0; i < arry.Count; i++)
            //{
            //    Console.WriteLine(arry[i]);
            //}
            foreach
            //foreach (object item in arry)
            //{
            //    Console.WriteLine(item);
            //}



            //Add
            //ArrayList arry1 = new ArrayList();
            //ArrayList arry2 = new ArrayList();
            //arry2.Add(1);//1
            //arry2.Add(2);//2
            //arry2.Add(3);//3
            //arry1.Add(0);//0
            //arry1.AddRange(arry2);
            //arry1.Add(4);//4
            //foreach (object item in arry1)
            //{
            //    Console.WriteLine(item);//01234
            //}



            //ArrayList arry = new ArrayList();
            //Console.WriteLine(arry.Count);
            //arry.Add(1);
            //arry.Add(1);
            //arry.Add(1);
            //Console.WriteLine(arry.Count);
            //arry.Clear();
            //Console.WriteLine(arry.Count);



            //ArrayList arry = new ArrayList();
            //arry.Add(1);
            //arry.Add(2);
            //arry.Add(3);
            //arry.Add(4);
            //arry.Add(5);
            //Console.WriteLine(arry.Contains(4));
            //bool flag = false; 
            //for (int i = 0; i < arry.Count; i++)
            //{
            //    if ((int)arry[i] == 4)
            //    {
            //        flag = true;
            //        break;
            //    }
            //}
            //Console.WriteLine(flag);



            //ArrayList arry = new ArrayList();
            //arry.Add(1);
            //arry.Add(2);
            //arry.Add(3);
            //arry.Add(4);
            //arry.Add(1);
            //arry.Add(5);
            //Console.WriteLine(arry.IndexOf(1));
            //Console.WriteLine(arry.LastIndexOf(1));



            //ArrayList arry = new ArrayList();
            //arry.Insert(0, "A");
            //arry.Insert(0, "B");
            //arry.Insert(0, "C");
            //foreach (object item in arry)
            //{
            //    Console.WriteLine(item); 
            //}


            //ArrayList arry = new ArrayList();
            //arry.Add(1);
            //arry.Add(2);
            //arry.Add(3);
            //arry.Add(4);
            //arry.Add(1);
            //arry.Add(5);
            //foreach (var item in arry)
            //{
            //    Console.WriteLine(item);
            //}
            //Console.WriteLine("移除前---------------");
            //Console.WriteLine(arry.Count);
            //Console.WriteLine("---------------移除4");
            //arry.RemoveAt(arry.IndexOf(4));
            //foreach (var item in arry)
            //{
            //    Console.WriteLine(item);
            //}
            //Console.WriteLine("移除后---------------");
            //Console.WriteLine(arry.Count);
            //Console.WriteLine("---------------")



            //Hashtable hash = new Hashtable();
            //hash.Add("zh", "中国");
            //hash.Add("jp", "日本");
            //if (!hash.ContainsKey("zh"))
            //{
            //    //hash.ContainsValue("中国");
            //    hash.Add("zh", "中国");
            //}
            //hash.Remove("jp");
            //Console.WriteLine(hash.Count);
            //foreach (object item in hash)
            //{
            //    Console.WriteLine(item);
            //}
            //Console.WriteLine("-------------------转码后");
            //foreach (object item in hash)
            //{
            //    DictionaryEntry dic = (DictionaryEntry)item;
            //    Console.WriteLine(dic.Key + "................." + dic.Value);
            //}



            //SortedList sort = new SortedList();
            //sort.Add("1", "中国");
            //sort.Add("2", "日本");
            //sort.Add("3", "美国");
            //sort.Add("4", "英国");

            Console.WriteLine(sort["zh"]);
            arratlist
            //Console.WriteLine(sort.GetByIndex(0));
            //Console.WriteLine(sort.GetKey(0));
            //foreach (object item in sort.GetKeyList())
            //{
            //    Console.WriteLine("ket:{0}------------value:{1}",item,sort[item]);
            //}
            //foreach (object item in sort.GetValueList())
            //{
            //    Console.WriteLine(item );
            //}



            //Stack stack = new Stack();
            //stack.Push("A");
            //stack.Push("B");
            //stack.Push("C");
            //stack.Pop();
            //Console.WriteLine(stack.Count);
            //int j = stack.Count;
            //for (int i = 0; i < j; i++)
            //{
            //    Console.WriteLine(stack.Pop());
            //}
            //Console.WriteLine(stack.Count);
            //for (int i = 0; i < stack.Count; i++)
            //{
            //    Console.WriteLine(stack.Peek());
            //}
            //Console.WriteLine(stack.Count);
            //foreach (object item in stack)
            //{
            //    Console.WriteLine(item);
            //}


            //Queue q = new Queue();
            //q.Enqueue(1);
            //q.Enqueue(2);
            //q.Enqueue(3);
            //q.Enqueue(4);
            //q.Enqueue(5);
            //Console.WriteLine(q.Dequeue());
            //foreach (object item in q)
            //{
            //    Console.WriteLine(item);
            //}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值