Tuesday, August 10, 2010

Optional Parameters with Example

Optional Parameters

Optional parameters allow you to omit arguments to member invocations, whereas named arguments is a way to provide an argument using the name of the corresponding parameter instead of relying on its position in the parameter list.


class Employee

    public void Create(string name, string job="Software Engineer", int salary=50000)


The above class contains a method Create, it has three parameters.  It allows to call this method like as following

obj.Create("Jobin John");

Other two parameters  declared as optional parameteds, so if we doesn't suppy values for it, automatically takes initialized values of that parameters.

No comments: