I've recently used this site to get the code to extract an array of property values from a list of objects (I've searched again and again and can't find the original post or help on the update :()
This is the result:
qtyArray.AddRange(plan.Components.Select(c => c.qty.HasValue ? (int)c.qty.Value : 0).ToArray());
Problem is, I have other properties i'm outputting into parallel arrays to pass to a datasource but would prefer to ignore any false 'active' properties. So for all the arrays do something like above, but only where c.active == true:
plan.Components.Select(c => c.qty.HasValue ? (int)c.qty.Value : 0 **WHERE c.active**)
Can anyone help?
What about this:
plan.Components.Where(c => c.active).Select (c => c.qty.HasValue ? (int)c.qty.Value : 0 )
It should do the required filtering.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With