开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜