Question

I have a collection of objects to which I'd like to just add a new property. How do I do that with LINQ?

Was it helpful?

Solution

var a = from i in ObjectCollection select new {i.prop1, i.prop2, i.prop3, ..., newprop = newProperty}

OTHER TIPS

I don't think that you can using pure LINQ. However, if you're doing this sort of thing a lot in your code you may be able to make this work with reflection.

Why do you want to add the extra property? Or, put a different way, what do you intend to do with the property once you have it in your new IEnumerable source?

If you need it for data binding, I have a helper class that might help you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top