linq query select where c#
var queryLondonCustomers = from cust in customers
where cust.City == "London"
select cust;
linq query select where c#
var queryLondonCustomers = from cust in customers
where cust.City == "London"
select cust;
where in used in linq c#
var myInClause = new string[] {"One", "Two", "Three"};
var results = from x in MyTable
where myInClause.Contains(x.SomeColumn)
select x;
// OR
var results = MyTable.Where(x => myInClause.Contains(x.SomeColumn));
linq where c#
// The Where can be used to filter what you need,
// if you want multiple items to be returned change
// your variable to a list for example and replace FirstOrDefault with ToList
// For list of integers
List<int> myList = new List<int>(){1,2,3,4};
int singleItem = myList.Where(x => x == 1).FirstOrDefault();
// For list of custom object
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();
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us