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?

有帮助吗?

解决方案

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();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top