Hi,
No, struct won't do. Why?
1. This is not what we want to do. It makes the code unclear. I don't have
method with default parameters. What I have is method with a mandatory
parameter of some struct type .
2. I can't have default values for the structure fields, because I can't
have a default constructor (thus I can't have initializing expressions in
the fields' declarations) . Because of the latter I have to make as many
overloads of that structure's constructor as many defaults parameters I
have. So, where is the benefit?. Better to overload my method.
Classes doesn't have these disadvantages, but classes are reference types,
which opposites the nature of the parameters, which are local copies of the
actual ones passed to the function.
Again, why we have to workaround something which has to be feature of any
modern language I believe?
B\rgds
100
"Zürcher See" <aq****@cannabismail.com> wrote in message
news:10***************@fuchs.cyberlink.ch...
Make a struct with the parameters and pass the struct to your method
"100" <10*@100.com> schrieb im Newsbeitrag
news:uB**************@TK2MSFTNGP09.phx.gbl... I's too boring. If I have method and I want to have for say 3 of the
parameters default values I have to make 3 dummy overloads. Those
overloads pollute the code and make the source files bigger.
It's a shame that c# doesn't have default parameters. I don't warry
about the performance hopefully calls to those methods will be inlined by the
JITter.
I think default parametters are not CLI compliant, but we may still
benefit from them for internal stuff.
B\rgds
100
<an*******@discussions.microsoft.com> wrote in message
news:04****************************@phx.gbl... What's the problem with method overloading ?
Actually, it's the only solution.
The framework does it all over the place.
You don't have to worry about the extra method and extra
method call.
Greetings,
BV.
>-----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
>
>
>c
>
>
>.
>