Question Variable Initialization

renegrin

New member
Joined
Jul 15, 2010
Messages
1
Programming Experience
3-5
I'm confused with the difference between the following two statements:

Dim clone1 As New Dictionary(Of TKey, TValue)()

Dim clone1 As Dictionary(Of TKey, TValue) = New DMVUpdateParameters(Of TKey, TValue)()


What's the difference? Maybe my old VB6 mind is interfering.

Renegrin
 
The difference is that the first line declares a Dictionary variable, creates a Dictionary object and assigns that object to the variable, while the second line declares a Dictionary variable, creates a DMVUpdateParameters object and assigns that object to the variable. It's important to realise that this:
VB.NET:
Dim clone1 As New Dictionary(Of TKey, TValue)()
is simply shorthand for this:
VB.NET:
Dim clone1 As Dictionary(Of TKey, TValue) = New Dictionary(Of TKey, TValue)()
so, as you can see, the first line is exactly the same as the second line except for the type of the object that is created. Presumably the DMVUpdateParameters class inherits the Dictionary class.
 
If you want to know what a Dictionary is and how it works then read the documentation for the Dictionary class. If you want to know what any type or member is and how it works then read the documentation for that type or member. If you do that and you still don't understand or you need clarification then by all means post but your course of action should always be look first, ask questions later.
 
By the way, what a Dictionary is has nothing to do with initialisation of variables, which is the topic of this thread, so that question belongs in a mew thread with a new topic.
 
Back
Top