Question

I would like to get the first object in an ObservableCollection like this:

Customer pCustomer = new Customer();
pCustomer = this.CustomerDataObject.First;

public ObservableCollection<Customer> CustomerDataObject
{
    get
    {
        return mCustomerDataObject;
    }
}

Is it possible at all?

Était-ce utile?

La solution

First is not a property it is an extension method.

var first = CustomerDataObject.First();

If no element, First will throw exception, You can use FirstOrDefault in that case which will return null.

var firstOrDefault = CustomerDataObject.FirstOrDefault();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top