Re: optional param in Method



"Rick" <RickREMOVETHIS@xxxxxxxxxxxxxxxxxx> schrieb
VS2005 Pro

I have confusing results from an optional parameter in a method.
Public Shared Function Parameter(ByVal parameterName As String,
ByVal parameterValue As Object, Optional ByVal db_Type As FbDbType =
Nothing) As FbParameter

FbDbType is an enumeration with 0 = "Array", 1 = "BigInt" etc.

When I call this method and omit the db_Type value like this:

myParam = Parameter("param1", 1234)

the value of db_Type is "Array" rather than "nothing" like I expect.
I suspect this has something to do with the fact that the db_Type is
really an Integer type and cannot be initialized to "Nothing". I
need to test if db_Type has been initialized in my method and assign
it to a var in the method.

Is my suspicion correct and is there some other way to do this?

Do not use the keyword Nothing with value types. It is allowed but it should not be. An Enum is a value type. Assigning Nothing to a value typed variable means assigning the "default value". An enum is stored as an Integer value. An Integer's default value is 0 (zero). So, the signature is identical to:

.... Optional ByVal db_Type As FbDbType = 0....


Armin

.