我有List
,例如:
public class User
{
public string Name { get; set;}
public bool IsShow { get; set;}
}
List<User> myList = new List<User>();
myList.Add(new User(){Name = "FUser", IsShow = true});
myList.Add(new User(){Name = "FUser2", IsShow = true});
myList.Add(new User(){Name = "FUser3", IsShow = true});
myList.Add(new User(){Name = "BUser", IsShow = true});
myList.Add(new User(){Name = "FUser4", IsShow = true});
如何按特定条件过滤列表中的元素,然后使用 Linq 更改它们的属性?
我过滤元素:
myList.AsEnumerable().Where(u => u.Name.Contains("/" + F + "/");
所以,我想要, ,和的属性IsShow = true
。"FUser"
"FUser2"
"FUser3"
"FUser4"
IsShow = false
BUser
没有循环,Linq 可以吗?