c# linq where code example
Example 1: linq c# where condition
var query = MemberTable.Where(x=>x.sex.Equals(Sex))
if (members != null)
query = query.Where(x=>members.Contains(x.membercode))
query.ToList();
Example 2: linq query select where c#
var queryLondonCustomers = from cust in customers
where cust.City == "London"
select cust;
Example 3: linq where c#
List<int> myList = new List<int>(){1,2,3,4};
int singleItem = myList.Where(x => x == 1).FirstOrDefault();
List<CustomClassName> myList = new List<CustomClassName>()
{
new CustomClassName(){ MyIntProp = 1, MyStringProp = "blah" },
new CustomClassName(){ MyIntProp = 2, MyStringProp = "blah2" },
};
CustomClassName singleItem = myList.Where(x => x.MyIntProp == 1).FirstOrDefault();
CustomClassName singleItemTwo = myList.Where(x => x.MyStringProp == "blah2").FirstOrDefault();