Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
View design
Message
From
23/01/2011 12:35:50
 
 
To
23/01/2011 10:28:45
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01496981
Message ID:
01497070
Views:
32
>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 ? :-}
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform