C
CMM
Dim s As String = String.Empty
Dim s As String = DoSomething()
is the answer.
Seems to me that you're still holding on to the VB.Classic notion of
"Declaring" variables at the top of a method rather Instantiating them when
you need them in a block so that they're destroyed when the block ends.
If Condition Then
Dim s As String = DoSomething()
'do work
End If
The benefits of this coding style are many and hard to explain unless you
work in a team or are otherwise mindful of future developers maintaining
your software. Curious, do you work in a team or alone?
...
s = DoSomething()
///
... initializing 's' is completely useless in the sample above and adds
additional initialization overhead. That's why I wrote that it doesn't
make sense to initialize /every/ string variable with 'String.Empty' or ""
Dim s As String = DoSomething()
is the answer.
Seems to me that you're still holding on to the VB.Classic notion of
"Declaring" variables at the top of a method rather Instantiating them when
you need them in a block so that they're destroyed when the block ends.
If Condition Then
Dim s As String = DoSomething()
'do work
End If
The benefits of this coding style are many and hard to explain unless you
work in a team or are otherwise mindful of future developers maintaining
your software. Curious, do you work in a team or alone?