1
Question Body:

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

Edit
avatar
asked15 years ago

    Leave a Comment

    [named hyperlinks] (https://example.com)
    **bold**
    _italic_

    3 Answer

    0
    var a = from i in ObjectCollection select new {i.prop1, i.prop2, i.prop3, ..., newprop = newProperty}
    
    Edit
    avatar
    answered15 years ago
    0

    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.

    Edit
    avatar
    answered15 years ago
    0

    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.

    Edit
    avatar
    answered15 years ago

    Your Answer

    Drop files here or click to upload.
    undraw-questions

    Disilab for your Teams

    – Collaborate and share knowledge with a private group.

    Create a free Team