LinQ基本使用:查询泛型集合

查询泛型集合示例
本文展示了一个使用C#查询泛型集合的具体示例。通过LINQ查询语法和FindAll方法,筛选出字符串长度大于3且首字母为数字的元素,并进行排序与输出。
#region 查询泛型集合
            Console.WriteLine("查询泛型集合\r\n");
            List<string> slist = new List<string>();
            slist.Add("lanmda");
            slist.Add("Happy");
            slist.Add("abc");
            slist.Add("birthday");
            slist.Add("4birthday");

            //查询字符串中长度大于3的且首字母是数字的
            var listchild = from str in slist
                            where str.Length > 3
                            where Char.IsNumber(str.Substring(0, 1).ToCharArray()[0]) == true
                            orderby str ascending
                            select str;
            foreach (var item in listchild)
            {
                Console.WriteLine(item);
            }


            List<string> c1 = slist.FindAll(n => n.Length > 3);
            foreach (var item in c1)
            {
                Console.WriteLine(item);
            }
            #endregion

转载于:https://www.cnblogs.com/Sky-cloudless/archive/2012/04/24/2467938.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值