Hi people! At the moment, I use this type of routine in VB:
VB Code:
  1. Sub Test()
  2.     Dim obj as Object
  3.  
  4.     Try
  5.         ' obj.new
  6.         ' obj.property
  7.     Catch ex as Exception
  8.         ' handle obj exception
  9.     Finally
  10.         If not (obj is nothing) then
  11.             obj = nothing
  12.         End If
  13.     End Try
  14. End Sub
From doing the same in this c# language, this:
Code:
void Test() {
    object obj

    try {
        // obj.new
        // obj.property
    }
    catch Exception ex {
        // handle obj exception
    }    
    finally {
        if (obj !=null) {
            obj = null
        }
    }
}
Generates a "Use of unassigned local variable" exception for the obj variable. It looks like my choices are:

1) To declare and set with the New() keyword, any objects, right at the top of the method - which means a performance hit as I'm not just referencing them only when I need to, or...

2) To put the calls to set the object to null within only the try block. Then if an exception's generated before this line, just leave it to the garbage collector only to clear the object from memory.

Surely this can't be right can it? I though C# was at least the same, if not more efficient than VB?