开发者

linq select within where clause

开发者 https://www.devze.com 2023-02-22 18:51 出处:网络
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

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号