default list for various data types


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.

LVL 13
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
all numeric data defaults to 0

>my goal is to not be redundant if i declare like Dim total as Double = 0
you are actually not redundant with that, but rather show best practice, as you clearly show what the value is initialized with, and avoid compiler warnings due to uninitialized values.

Also, in the final .exe it will be the same, as the compiler will put the (default) assignment anyhow.
newyuppieAuthor Commented:
what does string default to?
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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).
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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.
newyuppieAuthor Commented:
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:
newyuppieAuthor Commented:
great, thanks to both of you for the answers. i will increase points to split between both. thanks again
All Courses

From novice to tech pro — start learning today.