optional Arguments for beginners

Posted by Sakthi.Singaravel under C# category on | Points: 40 | Views : 1074
Optional Arguments

In Functions you can define the arguments default values, that arguments called "Optional arguments".
If in case no value is supplied to it, a default value is used for the same.
Example as follows,

class opt_arg
static void main(String[] args)
Console.WriteLine("optional Arguments");
Console.WriteLine(calculate(15));// Here the Second argument takes default value
static int calculate(int a, int b=9)
return a+b;

Output :

optional Arguments

Comments or Responses

Posted by: Sandeepkasar on: 4/12/2012 Level:Starter | Status: [Member] | Points: 10

this code is not working
I got an error Error...Default parameter specifiers are not permitted

Login to post response