知识点

        static void Main(string[] args)
        {
            //通过泛型可以限制集合中存放的数据的类型
            List<int> list = new List<int>();
            list.Add(10);
            list.Add(20);
            list.Add(20);
            Console.WriteLine( list.Max());
            Console.WriteLine(list.Min());
            Console.WriteLine( list.Sum());
            Console.WriteLine(list.Average());
          

            List<string> strList = new List<string>();
            strList.Add("helloworld!");
            strList.Add("hello");

            for (int i = 0; i < list.Count; i++)
            {

                Console.WriteLine(list[i]);
            }
            //返回值就是整形数组
           //int[] lists= list.ToArray();

            Console.ReadKey();

        }

 

 

        static void Main(string[] args)
        {
            #region Myregion
            // Dictionary<string, string> dict = new Dictionary<string, string>();
           // dict.Add("yqq","杨巧巧");
           // dict.Add("lxf", "刘晓飞");
           // dict.Add("zl", "张兰");
           // if(!dict.ContainsKey("ly"))
           // {
           // dict.Add("ly","刘一");
           // }
           //Console.WriteLine( dict.ContainsKey("zl"));
           //Console.WriteLine(dict["zl"]);

           //foreach (string item in dict.Values)
           //{
           //    Console.WriteLine(item);
            //}
            #endregion

            #region MyRegion2

            Dictionary<string, Person> dict = new Dictionary<string, Person>();
            Person p1 = new Person() { Name = "张兰", Age = 18 };

            dict.Add(p1.Name, p1);
            Console.WriteLine((dict[p1.Name]).Name+"的年龄是:"+dict[p1.Name].Age);

            //1遍历键
            foreach (string item in dict.Keys)
            {
                Console.WriteLine(item);
            }
            //2遍历值
            foreach (Person item in dict.Values)
            {
                Console.WriteLine(item);
            }
            //3键和值同时遍历
            foreach (KeyValuePair<string, Person> kv in dict)
            {
                Console.WriteLine("键:{0},值:{1}",kv.Key,kv.Value);
            }
            #endregion
            //4.计算字符串中每种字符出现的次数。(面试题)“welcome to china! this

//is a beautiful county, i think you will like it.here is The great wall

//”提示:Dictionary<char,int>

            string str = "Welcome to china! this is a beautiful county, i think you will like it.here is The great wall";
            str = str.ToLower();
            Dictionary<char, int> dict2 = new Dictionary<char, int>();//
            //dict<'w',3>
            //统计字符出现的次数
            for (int i = 0; i < str.Length; i++)
            {
                if (char.IsLetter(str[i]))
                {
                    if (dict2.ContainsKey(str[i]))
                    {
                        dict2[str[i]]++;
                    }
                    else
                    {
                        dict2.Add(str[i], 1);
                    }
                }
            }

            foreach (KeyValuePair<char, int> kv in dict2)
            {

                Console.WriteLine("字符:{0},出现了{1}次",kv.Key,kv.Value);
            }

                Console.ReadKey();


        }
    }
    public class Person
    {
        public string Name
        {
            get;
            set;
        }
        public int Age
        {
            get;
            set;
        }

 

 

  static void Main(string[] args)
        {
            ArrayList arrayRandom=new ArrayList();
            int index=0;
            //通过Random产生的随机数是伪随机数,伪随机数产生需要一个种子。
            //只要种子一样每次产生的随机数就都是一样的。
            Random random=new Random();
          
           
            while (arrayRandom.Count < 10)
            {
               // Random random = new Random();
                int rd=random.Next(1,101);
                index++;
                if (rd % 2 == 0)
                {
                    if (!arrayRandom.Contains(rd))
                    {
                        arrayRandom.Add(rd);
                    }
                }
            }
            for (int i = 0; i < arrayRandom.Count; i++)
            {
                Console.WriteLine(arrayRandom[i]);
            }
            Console.WriteLine("一共循环了:{0}次",index);

            Console.ReadKey();

        }

 

 

 static void Main(string[] args)
        {
            Console.WriteLine("请输入一个数:");
            string number=Console.ReadLine();

            //-------------------------------------------
            string str = "1壹 2贰 3叁 4肆 5伍 6陆 7柒 8捌 9玖 0零";
            Dictionary<char, char> dict = new Dictionary<char, char>();
            string[] parts = str.Split(' ');
            //pars[0]---"1壹"
            //pars[1]----"2贰"
            //foreach (string item in parts)
            //{
            //    Console.WriteLine(item);
            //}

            for (int i = 0; i < parts.Length; i++)
            {
                dict.Add(parts[i][0], parts[i][1]);
               
            }
            //----------------------------------
            StringBuilder sb=new StringBuilder();
            for (int i = 0; i < number.Length; i++)
            {
                sb.Append(dict[number[i]]);//789
           
            }
            Console.WriteLine(sb.ToString());

                Console.ReadKey();


        }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值