Function

  • Thread starter Patrick Steele [MVP]
  • 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.
 
M

msnews.microsoft.com

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top