C#基础06

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Base06
{
    class Program
    {
        static void Main(string[] args)
        {
            //ArrayList 增加的时候是可以插入重复值
            // 输出的方式是有序的,从插入的顺序决定输出的顺序
            //ArrayList arry = new ArrayList();
            //arry.Add(1);
            //arry.Add(2);
            //arry.Add(3);
            //arry.Add(4);
            //arry.Add(5);
            // //输出
            // //1 for
            // for (int i = 0; i < arry.Count; i++)
            // {
            //     Console.WriteLine(arry[i]);
            // }
            // Console.WriteLine("-------------------");
            // //2 forwach
            // foreach (object item in arry)
            // {
            //     Console.WriteLine(item);
            // }

            //ArrayList arry1 = new ArrayList();
            //ArrayList arry2= new ArrayList();
            //arry2.Add(1);
            //arry2.Add(2);
            //arry2.Add(3);
            //arry1.Add(0);
            将多个集合整合成为一个集合
            里氏替换原则
            //arry1.AddRange(arry2);
            //arry1.Add(4);
            //foreach (object item in arry1)
            //{
            //    Console.WriteLine(item);
            //}

            //清空 empty  Clear
            //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);
            //判断当前的数据时候包含在当前的集合中
            // for   if  判断
            //ArrayList arry = new ArrayList();
            //arry.Add(1);
            //arry.Add(2);
            //arry.Add(3);
            //arry.Add(4);
            //arry.Add(5);
            //Console.WriteLine(arry.Contains(3));
            //假设没有找到对应的信息
            //bool flag = false;
            //for (int i = 0; i < arry.Count; i++)
            //{
            //    if ((int)arry[i]==3)
            //    {
            //        flag = true;
            //        break;
            //    }
            //}
            //Console.WriteLine(flag);

            //ArrayList arry = new ArrayList();
            //arry.Add(1);
            //arry.Add(2);
            //arry.Add(3);
            //arry.Add(4);
            //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(5);
            RemoveAt 根据下标删除
            Remove 根据对象删除
            //arry.RemoveAt(arry.IndexOf(4));
            //foreach (object item in arry)
            //{
            //    Console.WriteLine(item);
            //}

            //Console.WriteLine(arry.Count);
            //arry.Remove(1);
            //Console.WriteLine(arry.Count);

            //ArrayList arry = new ArrayList();
            //arry.Add("The");        
            //arry.Add("quick");
            //arry.Add("brown");
            //arry.Add("fox");         
            //arry.Add("jumped");
            //for (int i = 0; i < 10; i++)
            //{
            //    arry.Add(i);
            //    Console.WriteLine("-----------"+arry.Capacity);
            //    arry.TrimToSize();
            //    Console.WriteLine("-----------" + arry.Capacity);
            //    Console.WriteLine("--------------------------");
            //}

            //键值对  键名不能重复  如果重复 则后加入的  替换前 加入的
            //编写  编译  运行
            //Hashtable  保存的单独的键值对的类型就是DictionaryEntry类型
            //Hashtable hash = new Hashtable();
            //hash.Add("zh", "中国");
            //hash.Add("jp", "德国");
            //Console.WriteLine(hash["zh"]);
            //if (!hash.ContainsKey("zh"))
            //{
            //    hash.Add("zh", "中国");
            //}
            //hash.Remove("jp");
            //Console.WriteLine(hash.Count);
            //foreach (object item in hash)
            //{
            //    DictionaryEntry dic = (DictionaryEntry)item;
            //    Console.WriteLine(dic.Key+"-----"+dic.Value);
            //}

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

            //Console.WriteLine(sort["zh"]);
            //arraylist
            //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");//会对A产生压栈作用
            //stack.Push("C");//会对B产生压栈作用
            //移除栈顶元素
            //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.Count);
            //}

            //foreach (object item in stack)
            //{
            //    Console.WriteLine(item);
            //}

            //队列 先进先出
            //Queue q = new Queue();
            //q.Enqueue(2);
            //q.Enqueue(1);
            //q.Enqueue(3);
            //q.Enqueue(4);
            //q.Enqueue(5);
            //Console.WriteLine(q.Dequeue());
            //foreach (object item in q)
            //{
            //    Console.WriteLine(item);
            //}



            //1.使用ArrayList创建个数为10的集合,并要求用户输入信息。根据用户输入的名称进行删除,最后循环输出。
            //ArrayList arry = new ArrayList();
            //for (int i = 0; i < 10; i++)
            //{
            //    arry.Add(i);
            //}
            //Console.WriteLine("请输入对应信息");
            //int n = Int32.Parse(Console.ReadLine());
            //arry.Remove(n);
            //foreach (object item in arry)
            //{
            //    Console.WriteLine(item);
            //}

            //2.使用Hashtable创建个数为由用户确定输入个数的集合,键为自动增长列,值为用户输入。根据用户输入的值进行删除。
            //Console.WriteLine("请输入集合的个数:");
            //int n = Int32.Parse(Console.ReadLine());
            //Hashtable hash = new Hashtable();
            //for (int i = 0; i < n; i++)
            //{
            //    Console.WriteLine("请输入第" + i + "的值:");
            //    int s = Int32.Parse(Console.ReadLine());
            //    hash.Add(i, s);
            //}
            //Console.WriteLine("请输入你要删除的值:");
            //int c = Int32.Parse(Console.ReadLine());
            //hash.Remove(c);
            //foreach (object item in hash)
            //{
            //    DictionaryEntry dic = (DictionaryEntry)item;
            //    Console.WriteLine("第"+dic.Key+"个输入的" + "-----" + "值为:"+dic.Value);
            //}

            //3.使用Stack创建一个个数为100的集合,循环输出,并且下标数字是偶数的进行删除。
            //Stack stack = new Stack();
            //for (int i = 0; i < 100; i++)
            //{
            //    stack.Push(i);
            //    if (i % 2 == 0)
            //    {
            //        stack.Pop();
            //    }
            //}
            //foreach (object item in stack)
            //{
            //    Console.WriteLine(item);
            //}

            //4.使用Queue创建一个个数为100的集合,循环输出,并且下标数字是奇数的进行删除。
            //Queue q = new Queue();
            //for (int i = 0; i < 100; i += 2)
            //{
            //    q.Enqueue(i);

            //    q.Peek();

            //}
            //foreach (object item in q)
            //{
            //    Console.WriteLine(item);
            //}
            
            Console.ReadKey();
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值