Post

VB.NET Whidbey - The TryCast operator.

Introducing the TryCast operator (similar to the as operator in C#).  Paul Vick explains the specifics on this and I urge you to visit his site for further details.  Suffice to say, this one is definitely on my list of tools I’ll be adding to my arsenal.  However, it does bring up an interesting question (or two).

We will have the following operators:

  • CType
  • DirectCast
  • TryCast

Looks like one of those is out of place, doesn’t it?  Wouldn’t the following list look nicer?

  • Cast
  • DirectCast
  • TryCast

It seems that it would be simple enough to alias Cast with CType and give the developer a choice between which one they want to use.

And while we’re at it, how about the TryDirectCast operator?

Really, the point to this is to ask how the decision process works when deciding what to call new keywords in VB.NET.  Paul stated in a comment on his blog that he has thought about discussing that very subject, so stay tuned ;-)

This post is licensed under CC BY 4.0 by the author.