第三十五讲 LINQ 语法(二) 实例补充

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

namespace Con35
{
    class Program
    {
        static void Main(string[] args)
        {
            List<student> stus = new List<student>() {   
                new student(1,"张小三",new List<int>(){33,78,90},"1001"),  
                new student(2,"王小三",new List<int>(){65,66,67},"1002"),  
                new student(3,"李小三",new List<int>(){54,78,67},"1003"),  
                new student(4,"赵小三",new List<int>(){65,32,21},"1004"),  
                new student(5,"刘小三",new List<int>(){90,78,90},"1005"),  
                new student(6,"田小三",new List<int>(){65,78,88},"1006"),  
                new student(7,"张中三",new List<int>(){65,44,90},"1007"),  
                new student(8,"王中三",new List<int>(){55,78,90},"1008"),  
                new student(9,"张小四",new List<int>(){65,78,89},"1008"),  
                new student(20,"张小五",new List<int>(){65,44,77},"1005"),  
                new student(10,"张小六",new List<int>(){32,78,90},"1004"),  
                new student(11,"张小七",new List<int>(){65,55,66},"1007"),  
                new student(12,"张小八",new List<int>(){70,78,77},"1002")  
            };
            Console.WriteLine("\n============泛型类型转换实例================\n");
            List<string> ls = (from s in stus
                               select s.stuName).Cast<string>().ToList<string>();//糊里糊涂的

            foreach (string s in ls)
            {
                Console.WriteLine(s);
            }

            Console.WriteLine("\n=========Lambda表达式在Linq中的应用实例1==========\n");
            string[] array = {"abc","小二黑","中国" };
            var ls2 = array.Select(st => st);
            foreach (string ss in ls2)
            {
                Console.WriteLine(ss);
            }
            Console.WriteLine("\n=========Lambda表达式在Linq中的应用实例2==========\n");
            var ls3 = array.Where(x => x != "abc");//.Select(x => x);可有可无
            foreach (string y in ls3)
            {
                Console.WriteLine(y);
            }


            Console.ReadKey();
        }
    }
    /// <summary>
    /// 学生类
    /// </summary>
    public class student
    {
        public int stuId;//学生编号  
        public string stuName;//学生姓名  
        public List<int> score;//学生成绩单  
        public string bjNum;//班级编号  

        public student(int sid, string sna, List<int> sco, string bjn)
        {
            this.stuId = sid;
            this.stuName = sna;
            this.score = sco;
            this.bjNum = bjn;
        }
    }  
}
有关Lambda表达式树的理解,头大,收集了几个前人有关树讲解,请参考,有好的参考资料帮忙提供个连接,谢过!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值