What is the difference between declaring a variable new
like
andCode:Dim variable1 As New String
Thanks!Code:Dim variable1 As String?
Printable View
What is the difference between declaring a variable new
like
andCode:Dim variable1 As New String
Thanks!Code:Dim variable1 As String?
You don't actually declare a variable as New. Declaring a variable is declaring a variable. Using the New keyword means that you are also creating an object and assigning it to the variable you just declared. This:is actually just shorthand for this:vb.net Code:
Dim obj As New ObjectYou can see that the actual declaration, on the left of the "=" sign is exactly the same, but you are creating a new Object and using "=" to assign it to variable. You could expand that further to this:vb.net Code:
Dim obj As Object = New Objectand the result is still the same. This time the declaration and the assignment are completely separated but the code is still functionally equivalent.vb.net Code:
Dim obj As Object obj = New Object
Thank you very much, now that is clearer to me! thanks!