A
Alain Dekker
Hi,
I know that C# has not allowed the use of default parameters. So this
function prototype (which works nicely in C++) does not compile in C#:
void DoMyWork(bool bLoggedOn, int nAccessLevel = 0);
Briefly, what is the rationale behind not allowing default parameters? One
nice feature you can achieve with default parameters in C++ is recursive
functions as in:
void DoMyWork(bool bLoggedOn, int nLevel = 0)
{
if ((bLoggedOn) && (nLevel < 3))
{
nLevel++;
DoMyWork(bLoggedOn, nLevel);
}
else
{
// Do something when nLevel == 3?
}
}
I guess in C# you would do this using function overloads?
void DoMyWork(bool bLoggedOn, int nLevel)
{
// blah
}
void DoMyWork(bool bLoggedOn)
{
DoMyWork(bLoggedOn, 0);
}
Thanks,
Alain
I know that C# has not allowed the use of default parameters. So this
function prototype (which works nicely in C++) does not compile in C#:
void DoMyWork(bool bLoggedOn, int nAccessLevel = 0);
Briefly, what is the rationale behind not allowing default parameters? One
nice feature you can achieve with default parameters in C++ is recursive
functions as in:
void DoMyWork(bool bLoggedOn, int nLevel = 0)
{
if ((bLoggedOn) && (nLevel < 3))
{
nLevel++;
DoMyWork(bLoggedOn, nLevel);
}
else
{
// Do something when nLevel == 3?
}
}
I guess in C# you would do this using function overloads?
void DoMyWork(bool bLoggedOn, int nLevel)
{
// blah
}
void DoMyWork(bool bLoggedOn)
{
DoMyWork(bLoggedOn, 0);
}
Thanks,
Alain