Link to home
Start Free TrialLog in
Avatar of newyuppie
newyuppieFlag for Ecuador

asked on

default list for various data types

vb2005

when i declare a data type (e.g. Dim total as Double), what is the default value which variable total gets instanced with?

i would like a list or a link that tells which are the defaulted values for each data type. my goal is to not be redundant if i declare like Dim total as Double = 0, because maybe 0 is the default instanced value for that variable.

thanks
SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of newyuppie

ASKER

what does string default to?
Avatar of AlexFM
AlexFM

Default string value is Nothing, since this is reference type.
Default value of numeric type is 0, Boolean is false.

Test your program with Microsoft FxCop program, it shows all unnecessary initializations (among lot of other very useful things).
actually, in .net, variables all default to null object, hence are not initalialzed (my comment above was in the context of vb6, sorry)
you need to initalize all your variables, of any data type.
angel, so you mean i need to put a value to every declaration?

alex thanks for some clarifications.

finally, this question would obviusly go in the following direction:
is there a performace improvement if i declare and initialize every variable to its default value? i mean, does
Dim total as Double , and
Dim total as Double = 0

have any performance gains or any other benefit besides good coding practices?

thanks to both for your answers
Not exactly, Microsoft coding guidelines recommend to avoid unnecessary initialization of value types, if initial value is equal to default. All default null is right for reference types.

FxCop handles this situation:
http://www.gotdotnet.com/team/fxcop/
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
great, thanks to both of you for the answers. i will increase points to split between both. thanks again