Question: Is it good practice to declare object inside [`block scope`](http://msdn.microsoft.com/en-us/library/1t0wsc67.aspx) Condition

```
If item.DocType = 1 Then

     Dim objass As Assignment = DBFactory.GetAssignmentDB.AssignmentGetByID(vis.AssignmentID)                   

End If

```

OR should i declare object outside the if condition and then do assignment inside

```
 Dim objass As Assignment

 If item.DocType = 1 Then

     objass = DBFactory.GetAssignmentDB.AssignmentGetByID(vis.AssignmentID)

 End If

```

Answer: 
That entirely depends on the scenario.

If you want to use the variable within the condition only, then declare it inside the condition. If you want the variable to be used outside of the If statement, then it's scope must extend to outside the condition.

There is no 'good practice' for all scenarios. Sometimes it'll be inside, sometimes not - depends on it's usage.

<http://msdn.microsoft.com/en-gb/library/1t0wsc67.aspx>
Normally it is good coding style to declare variables in the smalles scope they are used.

I.e. in your example it depends if you want to access ´ass´ outside the if condition. - If you declare ´ass` inside it, you cannot access it outside.