LimitSymbol

//构造序列
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"}
};
//判断序列中所有元素的UserCode属性都大于1
bool isAll = users.All(itm => itm.UserCode > 1); //isAll=false
//判断序列中是否存在UserCode属性>=4的元素
bool isAny = users.Any(itm => itm.UserCode >= 4);//isAny=true

UserInfo tempUser = users[3];
//判断序列中是否包含tempUser元素
bool isContains = users.Contains(tempUser); //isContains=true
//输出结果
Response.Write(string.Format("All:{0} Any:{1} Contains:{2}",isAll,isAny,isContains));

posted @ 2013-01-18 16:50  yellowshorts  阅读(124)  评论(0编辑  收藏  举报