lambda表达式进行对象结合操作的实例详解


本文摘自PHP中文网,作者零下一度,侵删。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

1publicclass Person : BaseDomain

 2    {

 3long _id;

 4string firstName;

 5string secondName;

 6string comments;

 7 8public Person()

 9        {}

1011public Person(long id)

12        {

13this._id = id;

14        }

15public Person(long id,string firstName, string secondName)

16        {

17this._id = id;

18this.firstName = firstName;

19this.secondName = secondName;

20             comments = String.Empty;

21        }

22public Person(long id,string firstName, string secondName, string comments)

23             : this(id,firstName, secondName)

24        {

25this.comments = comments;

26        }

2728publicstring FirstName

29        {

30get { return firstName; }

31set { firstName = value; }

32        }

33publicstring SecondName

34        {

35get { return secondName; }

36set { secondName = value; }

37        }

38publicstring Comments

39        {

40get { return comments; }

41set { comments = value; }

42        }

43publicoverridestring ToString()

44        {

45returnstring.Format("FirstName: {0}\tSecondName: {1}\tComment: {2}", this.firstName, this.secondName, this.comments);

46        }

47     }

View Code

上面是测试需要的简单类型:Person

1

2

3

4

5

6

7

8

9

10

11

1var list = new List<Person>(5);

 2     list.Add(new Person(1,"咬金","程","拿斧子砍人的那个家伙");

 3     list.Add(new Person(2,"咬金","程","拿斧子砍人的那个家伙");

 4     list.Add(new Person(3,"貂蝉","王","3技能很厉害哦");

 5     list.Add(new Person(4,"昭君","李","适合打团战");

 6     list.Add(new Person(5,"亚瑟","毛","狠狠厚的肉");

 7 8//进行去重操作,需要先引入linq引用"using System.Linq; " 9var result_list = list.GroupBy(obj=>obj.FirstName).Select(g=>g.First()).ToList();

1011foreach(var item in result_list)

12    {

13        Console.WriteLine(item);

14     }

View Code

以上就介绍了Lambda表达式 使用lambda表达式进行对象结合的筛选操作,包括了Lambda表达式方面的内容,希望对.NET教程有兴趣的朋友有所帮助。

以上就是lambda表达式进行对象结合操作的实例详解的详细内容!

相关阅读 >>

代码分析:在.net core中使用ref和span<t>提高程序性能

uwp中使用composition api实现吸顶的实例教程

使用 vscode 编写 .net core 项目的实例教程

return后面的值不能为表达式吗?

浅谈wpf之binding表达式

net 使用 data.oracleclient 出现的错误

asp.net中sqldatareader生成动态lambda表达式的实例详解

c# 利用委托进行异步处理实例代码

克隆对象的方法实例教程

字符串分割的使用实例代码

更多相关阅读请进入《lambda》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...