Wrox Programmer Forums
|
Pro VB.NET 2002/2003 For advanced Visual Basic coders working .NET version 2002/2003. Beginning-level questions will be redirected to other forums, including Beginning VB.NET.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 2nd, 2005, 04:23 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anubhav.kumar
Default Declaration Difference

Hi forum

Can you please tell me the exact difference ( conceptual, behavioural, implementation and execution) between these two :

1. Dim x as integer
2. Dim x as New integer

in VB.net both are allowed. I am a little confused about two. In both cases x exhibits similar methods and properties. Why?

Anubhav Kumar
__________________
Anubhav Kumar
http://anubhavtimepass.blogspot.com/
 
Old July 5th, 2005, 07:46 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

These two declarations are no different. Because integers are simple native types they are implicitly instanciated. If you use more complex objects such as an ArrayList/DataSet, basically anything beyond simple types, then they are not instanciated:

Dim objDS1 As DataSet
Dim objDS2 As New DataSet

Now, objDS1 will be equal to null/Nothing while objDS2 will be a usable instance.

Also, these two behave the same, the first is just a shortcut method:

Dim objDS As New DataSet
Dim objDS As DataSet = New DataSet

-Peter
 
Old July 5th, 2005, 10:19 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anubhav.kumar
Default

hi forum

My real confusion lies in the fact that normally native or in built dada types do not need instanciation. But we are doing the same here

Dim x as integer=new integer() 'Although Dim x as integer works fine

Any comments?

Anubhav Kumar





Similar Threads
Thread Thread Starter Forum Replies Last Post
standalone declaration Jay Frank XML 5 September 28th, 2007 08:57 AM
xml declaration chroniclemaster1 XML 0 September 20th, 2007 02:00 PM
Declaration for DuplicateTokenEx BrianWren Pro VB 6 0 April 6th, 2007 03:54 PM
i get error during declaration of variable srivastavaavivek Forum and Wrox.com Feedback 1 March 12th, 2007 09:42 AM
Declaration Expected kenn_rosie ADO.NET 7 January 17th, 2006 03:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.