Default value attribute for type.

M

Mr. X.

In C# there is no optional parameter.
I use instead, what program that convert from VB.NET to C# recommand me to
do.

For optional parameter that is "Type" passed. What is the
defaultParameterValueAttribute -
compiler shouts that :
The DefaultValue attribute is not applicable on parameters of type
'System.Type' ...

The code :
[System.Runtime.InteropServices.OptionalAttribute,
System.Runtime.InteropServices.DefaultParameterValueAttribute(null)] ref
Type myType,

(Seems to long for setting optional attribute & default : null. in VB.NET it
was too short.
I think that instead of null, I should write something that "Type" can get
as a default).

How to solve the problem ?

Thanks :)
 
J

Jeff Johnson

In C# there is no optional parameter.
I use instead, what program that convert from VB.NET to C# recommand me to
do.

For optional parameter that is "Type" passed. What is the
defaultParameterValueAttribute -
compiler shouts that :
The DefaultValue attribute is not applicable on parameters of type
'System.Type' ...

The code :
[System.Runtime.InteropServices.OptionalAttribute,
System.Runtime.InteropServices.DefaultParameterValueAttribute(null)] ref
Type myType,

(Seems to long for setting optional attribute & default : null. in VB.NET
it was too short.
I think that instead of null, I should write something that "Type" can get
as a default).

How to solve the problem ?

MSDN says this about DefaultParameterValueAttribute: "Sets the default value
of a parameter when called from a language that supports default
parameters."

C# (before 4.0) is not one of those languages; you must use method
overloading.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top