Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VB.NET question I
Message
 
To
15/09/2009 11:06:06
General information
Forum:
Visual FoxPro
Category:
Visual FoxPro and .NET
Miscellaneous
Thread ID:
01424535
Message ID:
01424621
Views:
85
Hi Oscar,

>Is this good code (I mean, is it "bullet proof")?. It seems to work, but I understand the Return is executed AFTER the Finally. So how does it call a method on an allready disposed of object?

Return is not executed after the Finally. The way VB.NET works is that return produces a local variable with the name of the function and assigns the value. When the end of the procedure is reached, this value is returned automatically. The following code would be identical to your code:
Try
  myFunc = sStr.ToString
Secondly, assigning Nothing is not the same as disposing the object. Disposing means you call the Dispose method of the IDisposable interface. Usually this happens when you call the Close method. The clean way to deal with disposable objects would be
Using obj as new whatever()
  ' do something with obj
End Using
which is the same as using a try-block where the Finally section calls Dispose. However, StringBuilder is not a class that implements IDisposable. Unlike in VFP you don't have to clear references in .NET. When the object reference is assigned to a local variable, the reference will automatically be collected in the next pass of the garbage collection after the method returned.
--
Christof
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform