list<T>集合中的Remove()、RemoveAt()、RemoveRange()、RemoveAll()的用法


using
System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { List<string> str = new List<string> { "aa","a1","a2","bb","cc","dd","ee","ff"}; //str.Remove("aa");//指定要删除的内容 //str.RemoveAt(1);//用下表来指定要删除的内容此示例中删除的是bb内容 //str.RemoveRange(0, 2);//删除指定长度的内容此实例会删除aa和bb //str.RemoveAll(a => a.Contains("a"));//使用拉姆达表达式寻找包含a的内容 //然后将包含a的这一类文件全部删除. foreach (string item in str)//遍历显示要显示的内容 { Console.WriteLine(item); } Console.ReadLine(); } } }

要把这个删除放在最上面因为代码的执行时从上面往下的.

static void Main(string[] args)
        {
            List<string> str = new List<string> { "aa","a1","a2","bb","cc","dd","ee","ff"};
            List<string> str1 = new List<string>();
            str1.Add("mm");
           
            //添加
            //str.Add("66");//是将内容按照下标添加到最后一个.
            //str.AddRange(str1);//将一个list集合中的内容添加到另一个指定要添加的集合的后面
            str.

            foreach (string item in str)//遍历显示要显示的内容
            {
                Console.WriteLine(item);
            }

            Console.ReadLine();
        }

这个数插入希望可以帮到需要的你们

posted on 2019-03-26 13:59  码▄︻┻┳═一……世界  阅读(5340)  评论(0编辑  收藏  举报