Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

default list for various data types

Posted on 2006-06-26
8
Medium Priority
?
189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 600 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 143

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
 
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 1400 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

618 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