LIST排序去重转数组转字符串(字符串转数组转list)

 List li1 = new List { "8", "8", "9", "9", "0", "9" };

 

            string unit = "12,18,19,55,99";
            //List li2 = new List { "张三", "张三", "李四", "张三", "王五", "李四" };
            //List li3 = new List { "A", "A", "C", "A", "C", "D" };
            //List li4 = new List { "12", "18", "19", "19", "10", "19" };

 

            HashSet hs = new HashSet(li1); //此时已经去掉重复的数据保存在hashset中

 

            List b = hs.OrderBy(u => u).ToList();

 


            Console.WriteLine("li1去除重复后的值为");
            hs.ToList().ForEach(item => Console.WriteLine(item));

 

            Console.WriteLine("LIst转化为string排序");

 

            string dogCsv = string.Join(",", b.ToArray());
            Console.WriteLine(dogCsv);

 

            Console.WriteLine("---------字符串转数组----------");
            string[] unitArray = unit.Split(',');
            unitArray.ToList().ForEach(unitmi => Console.WriteLine(unitmi));

 


            Console.WriteLine("-----------数组转LIST------------");
            List listUnit = new List(unitArray);
            listUnit.Add("5");
            listUnit = listUnit.OrderBy(u =>Convert.ToDecimal( u)).ToList();
            listUnit.ForEach(u => Console.WriteLine(u));

            Console.Read();

LIST排序去重转数组转字符串(字符串转数组转list)_第1张图片

你可能感兴趣的:(c#后台)