View Single Post
  #4 (permalink)  
Old March 30th, 2011, 05:09 PM
Imar's Avatar
Imar Imar is offline
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I don't have the book so I can only guess, but could it be that the example is using the new Type inference system? Consider this example:

Code:
 
Class Person
  Public Sub New()
  End Sub
End Class
 
Class TestApplication
  Private Sub MethodName()
    Dim somePerson = GetPerson()
  End Sub
 
  Private Function GetPerson() As Person
    Return New Person()
  End Function
End Class
Despite what it looks like, the somePerson variable *is* strongly typed as a Person and not as an Object as the compiler infers the type of the variable based on the value that is assigned to it. Since GetPerson returns a Person, the somePerson variable is typed as a Person as well with this code.

This code works with Option Explicit and Option String set to On, as long as Option Infer is On as well.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!

Last edited by Imar; March 30th, 2011 at 05:53 PM..