
Signature
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant C++: C# to C++ Converter
Instant J#: VB.NET to J# Converter
> > dynamic_cast is the equivalent to the C# "as".
> >
[quoted text clipped - 10 lines]
> Arnaud
> MVP - VC
> In 'Managed C++ and .NET Development', Stephen Fraser gives a good
> explanation for why you should regard __try_cast as a development
> tool - basically, __try_cast exceptions will only occur if there are
> actual mistakes in your code.
We agree; that's the wole point : It's better to have an exception that
unmanaged behaviour and GC failure. Of course, it's still better to have an
error at build time, but you don't always have what you want ;-)
Now, if you are *really* performance worried (as much C++ developpers are,
generally without any measurement to prove that their worries are justified
;-), you can replace __try_cast by static_cast and *pray* not to have an
unnoticed invalid cast that will break hell loose in front of the client.
> But perhaps this is also close to what
> C# does.
AFAIK, __try_cast and C# casts do strictly the same thing.
Arnaud
MVP - VC
David Anton - 25 Oct 2005 20:40 GMT
Good point Arnaud.
It's apparent that we need to change conversion of the basic C# cast to use
__try_cast for the 2003 target. (It's in today's build).
Our conversion to the CLI target is correct in using safe_cast.

Signature
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant C++: C# to C++ Converter
Instant J#: VB.NET to J# Converter
> > In 'Managed C++ and .NET Development', Stephen Fraser gives a good
> > explanation for why you should regard __try_cast as a development
[quoted text clipped - 15 lines]
> Arnaud
> MVP - VC
Willy Denoyette [MVP] - 25 Oct 2005 21:00 GMT
>> In 'Managed C++ and .NET Development', Stephen Fraser gives a good
>> explanation for why you should regard __try_cast as a development
[quoted text clipped - 16 lines]
> Arnaud
> MVP - VC
__try_cast (MC++) is recast into safe_cast ( C++/CLI) , both generate
exactly the same IL instruction (castclass) just like an ordinary cast in
C#.
Willy.