Reputation: 10267
I have declared a property like so:
private int? platypusLocalId;
public int? PlatypusLocalId
{
get
{
return GetPlatypusLocalIDForPlatypusID(platypusID);
}
}
...expecting any reference to platypusLocalId, such as this:
Dictionary<int, string> duckBillPairs = GetAvailableDuckBillsForPlatypus(platypusLocalId);
...to call the accessor/getter; however, it is not being called and platypusLocalId is thus null when passed into GetAvailableDuckBillsForPlatypus().
Upvotes: 0
Views: 86
Reputation: 7522
Any reference to PlatypusLocalId will call the getter. However, you are using platypusLocalId (note the lowercase p), which means you are accessing the private field directly.
Properties aren't just used magically - you have to call them!
Upvotes: 5
Reputation: 18985
Check your case -- you're accessing the field platypusLocalId
directly, not the property PlatypusLocalId
. The field will be null as you haven't assigned it.
Upvotes: 5