Search code examples
c#linqobservablecollection

LINQ getting an item <t> from a collection


I need to receive a type from some LINQ which is assigned to a var at run-time, obviously, I could cast the var to my type myself, but I believe the LINQ is wrong, (maybe missing the Select?) can anyone point me in the right direction? Thanks

----- Code ------

   // there is only one active flag which is true in the collection...
    var selected = m_PersonCollection.Where(t => t.Active == true)

   // Thinking this is the way it is done...
    Person person = selected as Person;

Solution

  • var selected = m_PersonCollection.Where(t => t.Active == true).FirstOrDefault();