質問

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