Solved

default list for various data types

Posted on 2006-06-26
8
181 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:newyuppie
  • 3
  • 3
  • 2
8 Comments
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 150 total points
ID: 16986224
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.
0
 
LVL 13

Author Comment

by:newyuppie
ID: 16986310
what does string default to?
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 16986453
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).
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16986464
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.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 13

Author Comment

by:newyuppie
ID: 16986663
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
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 16986666
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/
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 350 total points
ID: 16986704
0
 
LVL 13

Author Comment

by:newyuppie
ID: 16986758
great, thanks to both of you for the answers. i will increase points to split between both. thanks again
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now