문제

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