Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
View design
Message
De
23/01/2011 12:35:50
 
 
À
23/01/2011 10:28:45
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01496981
Message ID:
01497070
Vues:
37
>Now, let me give you a little brain teaser
>
>What is an elegant way to dispose an object IF it implements IDisposable.
> You do not know whether the object implements IDisposable
>
>
>public void SomeMethod(ISomeInterface theObject)
>{
>	// do something with theObject
>	// and if theObject implements IDisposable
>	// dispose it
>}
Can't think of anything beyond the obvious:
if (theObject is IDisposable) ((IDisposable)theObject).Dispose();
//or
IDisposable d = theObject as IDisposable;
if (d != null) d.Dispose();
But presumably you've seen something else ? :-}
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform