Just wondering in the below function
public Dictionary<string, List<TrainingItem>> TrainingItems
{
set
{
trainingItems = SanitizeTrainingItems(value);
Results_Repeater.DataSource = trainingItems;
Results_Repeater.DataBind();
}
}
How does the value of (value) get past here and what is it. I mean there is no parameters to function but yet I am still passing a value in function I just don’t understand where it comes from ?
A property in C# simulates a data member when in reality it’s a set of accessor methods, specifically a
getaccessor and asetaccessor (unless the property is read-only). In most cases, a property is used to read, write or compute the value of a private field.A common use for a property would be:
The
getandsetblocks within the property definition represent the accessor method bodies that either read or write the value of_firstName. In thesetaccessor,valueis a contextual keyword representing the parameter of theset_FirstNameaccessor method generated by the compiler.Without properties, you would have to write these methods yourself, i.e., you’d have a
public string getFirstName();and apublic void setFirstName(string value);and you would call each method accordingly. A C# property is just a shortcut and gives you an easy to use mechanism to invoke the correct accessor.