ToArray

List<UserInfo> users = new List<UserInfo> {
new UserInfo{UserCode=1, UserName="User001", Password="001"},
new UserInfo{UserCode=2, UserName="User002", Password="002"},
new UserInfo{UserCode=3, UserName="User003", Password="003"},
new UserInfo{UserCode=4, UserName="User004", Password="004"}
};
//使用LINQ按降序排列泛型列表
//此时的query变量的类型是IEnumerable<UserInfo>类型
var query = from item in users
orderby item.UserCode descending
select item;
//使用ToArray方法将query转换为数组类型
UserInfo[] userArr = query.ToArray<UserInfo>();

Response.Write("ToArray的结果是:");
foreach (UserInfo user in userArr)
{
Response.Write(user.UserName + " , ");
}

 

 

public class UserInfo
{
public UserInfo()
{
//
//TODO: 在此处添加构造函数逻辑
//
}

public int UserCode { get; set; }

public string UserName { get; set; }

public string Password { get; set; }

}

你可能感兴趣的:(toArray)