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?

Was it helpful?

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();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top