linq例項 Group的使用(三)

2021-08-26 03:56:25 字數 681 閱讀 3462

測試用的class。

public class user private set } public string lastname private set } public user(string firstname, string lastname) }

linq的例子:

//準備資料。 user users = new user[3]; users[0] = new user(lastname: "liu", firstname: "andy"); users[1] = new user(lastname: "gao", firstname: "shan"); users[2] = new user(lastname: "liu", firstname: "patrick"); //使用linq來去。意思是在users, 把users符合條件的記錄,以lastname為group,放在usergroup裡。然後把usergroup返回給newusers var newusers = from u in users group u by u.lastname into usergroup select usergroup; //迴圈顯示。 foreach (var a in newusers) //a是group來的。可能包含不止乙個記錄。 ,",b.lastname, b.firstname)); }

linq例項 Group的使用(三)

測試用的class。public class user private set public string lastname private set public user string firstname,string lastname linq的例子 準備資料。user users new us...

linq例項 Group的使用

新建使用者類 using system using system.collections.generic using system.linq using system.text public string firstname private set public string lastname pr...

linq例項 Join的使用(四)

測試的class。public class user private set public string lastname private set public int id private set public user string firstname,string lastname,int i...