Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
VB.NET question I
Message
 
À
15/09/2009 11:06:06
Information générale
Forum:
Visual FoxPro
Catégorie:
Visual FoxPro et .NET
Divers
Thread ID:
01424535
Message ID:
01424621
Vues:
83
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform