Re: optional param in Method

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"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

.



Relevant Pages

  • Re: Question about "enums"
    ... enum loop ... Assigning values other than the constants declared in the enumeration are not necessarily undefined by the C Standard. ... The implementation must assign the enum to an integer type which will hold all the enumeration constants. ...
    (comp.lang.c)
  • Re: No enumeration data type in Fortran?
    ... C seems to say much more about enum constants than it does ... Definitely enum constants are int. ... C89 defined the term 'integer type' to include signed integer types, ...
    (comp.lang.fortran)
  • Re: promotion and narrowing integer conversion
    ... are assigned to smaller chars by implicit conversion; ... Assigning / converting a lager value to an object with smaller type ... It is not undefined behavior to assign an out of range value ... converted to is a signed integer type), ...
    (comp.lang.c)
  • Re: assignment of integer to enumerated value
    ... An enumerated type is a distinct type, ... conversion between any enum type and any integer type, ... Since the constants are of type int, ...
    (comp.lang.c)
  • Re: stratgies for organizing elements in a passed array
    ... You don't need f2003 to declare a set of named constants. ... Just use the normal syntax. ... and the enum type is some integer type sufficient to cover ... compatible with an integer type, ...
    (comp.lang.fortran)