I can not understand the following line: x => x.Id == _purchase.Centre.Id
the code is here:
private void LoadCentreOptions()
{
MaterialCentreDataSource mcds = new MaterialCentreDataSource();
List<MaterialCentre> centres = mcds.GetAll() as List<MaterialCentre>;
_blankCentre = new MaterialCentre()
{
Name = Strings.JournalViewModel_CreditedPartyOption_NotSpecified
};
centres.Insert(0, _blankCentre);
_centreOptions = new ReadOnlyCollection<MaterialCentre>(centres);
if (_purchase.Centre == null)
_purchase.Centre = _blankCentre;
else
_purchase.Centre = _centreOptions.First(x => x.Id == _purchase.Centre.Id);
}
here at the debugging time i am watching that X.Id is incremented .How it is possible?
The api
Firstis enumerating over the collection and applying the condition to check which one matches and then returns the first match.. So effectively the code translates toand if you understand LINQ its basically short for
To understand the exact implementation of First read Jon Skeets blogpost.