Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
The 'as' operator
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00852995
Message ID:
00853016
Vues:
17
Hi Claudio,

There isn't an equivalent of the "as" operator in VB.NET (unfortunately). What you need to do is check the type before you cast to it to make sure it will succeed.
Dim st As SomeType
If TypeOf obj Is SomeType Then st = CType(obj, SomeType)
If Not st Is Nothing Then ...
>Hey!
>
>what's the equivalent of C#'s "as" operator in VB.NET?
>
>in C#, we can do safe casts as in:
>
>
>human john = new Human();
>man anyman = john as man;
>if (anyman != null)
>   // john is man, so go ahead
>
>
>I know it is possible to use the "is" operator to check the type, but that's not optimized for performance. How's the optimized version for that in VB?
>
>TIA
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform