linq select within where clause
i have a class and a collection with in it.
class A
{
B[] boxes;
}
class B
{
string boxNumber;
}
Now, i ne开发者_开发知识库ed to create an object of type A that internally has B[] with only even box numbers. can anyone help me with the linq query?
This query should give you the boxes with even box numbers from a given A:
A myA = new A();
IEnumerable<B> BsWithEvenBoxNumbers = myA.boxes.Where(b => Int32.Parse(b.boxNumber) % 2 == 0);
Or, if you want the result in array form:
B[] BsWithEvenBoxNumbersArr = myA.boxes.Where(b => Int32.Parse(b.boxNumber) % 2 == 0).ToArray();
精彩评论