I got this assignment which to declare a method like this…
public List<Contact> GetLastContacts([int count = 20])
{
return this._entities.ContactsSet.ToList();
}
What I don’t understand and can’t find info about is [int count = 20] as parameter…
Anyone got an explanation on what they mean?
/Best regards!
int count = 20in a parameter declares it as a default value for the parameter. It makes the parameter optional for callers (or rather look optional for callers).So, in a method calling it you can do:
Or, to use a value to override the default:
See Named and Optional arguments on MSDN.