looks to me that perhaps there is a typo.
my understanding is that:
TypeB typeB = (TypeB)typeA
is faster assuming it does not throw an exception (i believe i read this in Richter's
book). i will use this method when i cast COM classes from one interface type to
another that i know is supported or some other cast that i expect to alway work
(because i figure i want an exception thrown in these cases).
otherwise i use:
Type B typeB = typeA as TypeB
if ( typeB == null )
return;
this method is slightly slower unless i expect that the cast will not be sucessful, in
that case it is faster than:
try {
TypeB typeB = (TypeB)typeA
}
catch (InvalidCastException)
{
}
that is how i understand things to work, i have never actually tested it
-joe
-----Original Message-----
From: Jekke Bladt [mailto:[EMAIL PROTECTED]
Sent: Wednesday, September 03, 2003 4:13 PM
To: [EMAIL PROTECTED]
Subject: [ADVANCED-DOTNET] Advantages to castclass opcode over isinst
All--
I'm ploughing through Don Box's CLR book and have come to part that leaves
me puzzled:
Box writes that the castclass opcode (generated by code like (Type)Object)
is far more computationally expensive than isinst (generated by obj1 = obj2
As Type) because of the potential overhead of invoking a structured error.
He then goes on to say that it's therefore preferrable to use ...As Type
style casting when you know at design time that a cast is possible and
(Type)Object casting when a runtime error is possible.
I don't understand the second part of the trade-off. If ...As Type style
casting can be tested for using the "is" keyword and castclass is so
process-intensive, why not always use "As" style casting?
TIA
--Jekke
==
"Of course we're going to be, as a movement, blowing things up and smashing
windows...I think it's perfectly appropriate for people to take bricks and
toss them through windows ... Hallelujah to the people who are willing
to do it."
--PETA Campaign Director Bruce Friedrich to wild applause from fellow
would-be eco-terrorists.
===================================
This list is hosted by DevelopMentor® http://www.develop.com
NEW! ASP.NET courses you may be interested in:
2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet
Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet
View archives and manage your subscription(s) at http://discuss.develop.com
===================================
This list is hosted by DevelopMentor® http://www.develop.com
NEW! ASP.NET courses you may be interested in:
2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet
Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet
View archives and manage your subscription(s) at http://discuss.develop.com