Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
View design
Message
 
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01496981
Message ID:
01497151
Views:
38
>>>>>>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 ? :-}
>>>>
>>>>
>>>>Seen something else ? Yes
>>>>
>>>>It's the latter of the obvious, but the compiler does it for you
>>>>
>>>>
>>>>public void SomeMethod(ISomeInterface theObject)
>>>>{
>>>>	using (theObject as IDisposable)
>>>>	{
>>>>		// do something here
>>>>
>>>>
>>>>	} //dispose 
>>>>}
>>>>
>>>>pages 32-33 http://www.amazon.co.uk/More-Effective-Specific-Software-Development/dp/0321485890/ref=sr_1_1?ie=UTF8&s=books&qid=1295806114&sr=8-1
>>>>
>>>>Also good to read http://www.amazon.co.uk/Effective-covers-4-0-Specific-Development/dp/0321658701/ref=sr_1_3?ie=UTF8&s=books&qid=1295806114&sr=8-3#_
>>>
>>>Question:
>>>I looked at the first book and ordered it then looked at the second one. I see this covers C#4 - but it's not clear whether it's a rehash of the first or whether it covers entirely different topics. Is it worth getting both ?
>>>TIA
>>
>>It's not a rehash. The first one covered new features in C# 2.0 and 3.0. The second covers new features in 4.0.
>
>Thanks Mike. Though I guess I'll wait to see how I like the first one before ordering the second......

Makes sense. I have the first two, have read good parts of both, and found them useful. But you are much more advanced in C# than I am so YMMV. If you look at the table of contents you will see that the general format is "Prefer X to Y." Seems like that might be useful even to someone who understands both X and Y.
Previous
Reply
Map
View

Click here to load this message in the networking platform