earwicker,
You will not be able to get around this in C#.
In VB, you could use the Optional keyword, but that will not create two
versions of your function (it places an attribute [opt] on the parameter),
which I believe is what you want. I imagne that Managed Extensions for C++
will give you the same result.
You could always place a property on your class that takes a boolean
value. This property, if set to true, would move the cursor appropriately
after the call to Write.
--
- Nicholas Paldino [.NET MVP]
All:
I know that C# does not directly support C++-style default parameters of the
form:
public void MyFunc( int inVal1, int inVal2 = 52 ) {...}
However, the 'workaround' that MS suggests in the documentation is to
compensate for this problem using overrides, i.e.:
// version 1
public void MyFunc( int inVal1 )
{
// here's my default value
int inVal2 = 52;
...
Quote:
}
// version 2, with user-supplied value
public void MyFunc( int inVal1, int inVal2 ) { ... }
Of course, this DOES work, but it's a ridiculous design solution in many
cases.
In my current project, I have a Write() function that ALREADY has almost 20
overrides to account for different input Types (a la Console.Write() in
.NET) . . . In addition, I need a boolean argument that specifies whether or
not the Terminal's cursor should/should not be relocated after the Write()
operation completes. This parameter should default to "true." Using the MS
suggestion would double the current number of overrides, which--I hope
you'll agree--is kinda goofy.
Any better ideas for a solution to the Daunting Dilemma of the Default
Parameter Value?
Thanks,
---earwicker
ps
Any comments on WHY this exceptionally useful C++ syntax was left
out/removed/discarded?