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表达式树的理解,头大,收集了几个前人有关树讲解,请参考,有好的参考资料帮忙提供个连接,谢过!
第三十五讲 LINQ 语法(二) 实例补充
最新推荐文章于 2024-07-12 23:08:38 发布