This post originated from an RSS feed registered with .NET Buzz
by Duncan Mackenzie.
Original Post: Paul Vick on two new operators in VB Whidbey
Feed Title: Code/Tea/Etc...
Feed URL: /msdnerror.htm?aspxerrorpath=/duncanma/rss.aspx
Feed Description: Duncan is the Visual Basic Content Strategist at MSDN, the editor of the Visual Basic Developer Center (http://msdn.microsoft.com/vbasic), and the author of the "Coding 4 Fun" column on MSDN (http://msdn.microsoft.com/vbasic/using/columns/code4fun/default.aspx). While typically Visual Basic focused, his blogs sometimes wanders off of the technical path and into various musing of his troubled mind.
In a recent post to his blog, Paul Vick discusses the new IsNot Operator (and the history/rational behind the Is operator, which allows you to write;
If myString IsNot Nothing Then
instead of
If Not myString Is Nothing Then
and, in another post, the new TryCast operator (which is like C#'s 'as' operator), which will allow you to save a bit of extra work (and produce a slight perf improvement in some situations) when checking to see if an object can be cast to a specific type .... allowing you to write;
Sub Print(ByVal o As Object)
Dim PrintableObject As IPrintable = TryCast(o, IPrintable)
If PrintableObject IsNot Nothing Then
PrintableObject.Print()
End If
...
End Sub
instead of the slightly less efficient
Sub Print(ByVal o As Object)
Dim PrintableObject As IPrintable
If TypeOf o Is IPrintable Then
PrintableObject = CType(o, IPrintable)
PrintableObject.Print()
End If
...
End Sub