views:

147

answers:

3

Which code snippet is better? and How? ['Better' on the basis of, readability, debug, code standards etc...,]

Dim Name As String = Employee.Name

or

Dim Name As String 
Name = Employee.Name
A: 

Well as they are both equivalent and both very simple I would expect the compiler to reduce them to the same thing so neither is really better.

Personally I feel the second has its advantages in that you can create several variables of one type in one line of code and then initialise them one after the other which for readable code is my preference. But if you only have one variable to initialise then the first is nice and concise as well.

RobV
+1  A: 

Combining declaration and assignement is generally thought to be the best approach (your first example)

Mitch Wheat
On debug mode, is it ok?
Dhana
A: 

As long as there is no null / empty or content checking between declaration and assignment, I prefer option number 1. Easier to read and less clutter.

Bjorn Isaksen