Doubt

  • Thread starter Thread starter Baskar RajaSekharan
  • Start date Start date
B

Baskar RajaSekharan

Hi,

Please let me know is ther any way to pass some default parameters to a
Method in C-Sharp without overloading the Method.
In VB we can done the above with the help of optional parameter . What's
the Equvelent in C-Sharp.

Note : Without Method OverLoading.

can you give me some sample.

Regards,
R.Baskar
 
There is sample from MSDN:

public static void UseParams2(params object[] list)
{
for ( int i = 0 ; i < list.Length ; i++ )
Console.WriteLine(list);
Console.WriteLine();
}

public static void Main()
{
UseParams2(1, 'a', "test");

}


Good luck
 
Hi Yura2000,

I believe this example is for variable number of arguments rather than
default parameters. Without overloading you cannot accomplish this in c#.

B\rgds
100

Yura2000 said:
There is sample from MSDN:

public static void UseParams2(params object[] list)
{
for ( int i = 0 ; i < list.Length ; i++ )
Console.WriteLine(list);
Console.WriteLine();
}

public static void Main()
{
UseParams2(1, 'a', "test");

}


Good luck
-----Original Message-----
Hi,

Please let me know is ther any way to pass some default parameters to a
Method in C-Sharp without overloading the Method.
In VB we can done the above with the help of optional parameter . What's
the Equvelent in C-Sharp.

Note : Without Method OverLoading.

can you give me some sample.

Regards,
R.Baskar




.
 
default parameter passing is not support in C#. What is your concern for not
using overloading, because this is probably your best option?
 
Back
Top