I am porting a C ++ program to C #. I just started to learn C #.
In C ++, if I define a constructor with a string parameter
class ProgramOption { public: ProgramOptions(const char* s=0); };
Then I can use the string parameter instead of ProgramOptions, for example
int myfucn(ProgramOption po);
myfunc("s=20;");
I can also use it as a default argument, for example
int myfunc(ProgramOption po=ProgramOption());
Unfortunately, in C # even I have
class ProgramOption { public ProgramOptions(const char* s=0) {...} }
I found that I can not use it as a default argument,
int myfunc(ProgramOption po=new ProgramOption());
and I cannot pass a string literal without explicit conversion, for example
myfunc("s=20");
Is this just not possible in C #, or can I implement some kind of method to make this happen? Thanks
source
share