简体   繁体   中英

Search an ObservableCollection by its objects fields

I'm developing a Windows Phone application with C#.

I have an ObservableCollection defined as follows:

public class StartingPersons
{
    public string ImagePath { get; set; }
    public string Name { get; set; }

    public static ObservableCollection<StartingPersons> GetPersons()
    {
        ...
    }
}

I want to search inside the ObservableCollection returned by StartingPerons.GetPersons(); by the field NAME.

How can I do that?

Thanks.

Something like:

IEnumerable<StartingPersons> matches = StartingPersons.GetPersons()
                                                .Where(p => p.Name == "...");

This isn't specific to ObservableCollection<T> though - basically you ought to look into LINQ and particularly LINQ to Objects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM