I'm going through an MVC tutorial and see this line of code at the beginning of a function:
private void PopulateDepartmentsDropDownList(object selectedDepartment = null) After testing it out, I can see that the function works, but I do not understand how the function parameter works. What does object selectedDepartment = null do?
I have done a general internet search and have not yet been able to locate an answer.
I guess my question really has two facets:
- What does the
= nullportion of the parameter do? - Is it something that can be done but not necessarily should be done?
= nullportion of the argument makes it an optional parameter, which will supply a default value of null for that parameter. It can be valid if you want polymorphic methods that allow for optional parameters.List<T>,Tis a type parameter. When you talk about a specific concrete list type, e.g.List<string> x = new List<string>();herestringis the type argument.