Function

  • Thread starter Thread starter Patrick Steele [MVP]
  • Start date Start date
P

Patrick Steele [MVP]

How can I specify default value of function parameter?

Use overloading:

public string GetInfo(int age, int type)
{
...
}

public string GetInfo(int age)
{
GetInfo(age, 5);
}

Now you can call GetInfo without supply a type and it will default to 5.
 
Is there any other method?

Patrick Steele said:
Use overloading:

public string GetInfo(int age, int type)
{
...
}

public string GetInfo(int age)
{
GetInfo(age, 5);
}

Now you can call GetInfo without supply a type and it will default to 5.
 
Back
Top