Property

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

I code in C# ... could someone explain what Type is being returned by the
VB.NET property below? I'm confused because the _session object is of type
Hashtable, and the Session is of type
System.Web.SessionState.HttpSessionState. The both appear to implement
ICollection, but don't you have to specify that in the definintion of a
VB.NET property? Or is that "implied" in VB.NET?

Thanks in advance.
-Mark

Shared _session as New Hashtable

Public Shared ReadOnly Property session()
Get
If IsNothing(System.Web.HttpContext.Current) Then
Return _session
Else
Return System.Web.HttpConext.Current.Session
End If
End Get
End Property
 
Gotta love that VB - it's returning type System.Object. VB allows you to
omit the type of a function with the result that it returns System.Object.

Hope that helps,

David Anton
Tangible Software Solutions Inc.
www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter
 
What is the Readonly keyword good for if I may ask? Is it just indicating
that the property doesn't have a set accessor?
 
The ReadOnly keyword (along with many other keywords in VB, such as
WriteOnly, Overloads) *should* not be required by the compiler (it's unneeded
in C#, for instance), but it is required and is part of the descriptive
redundancy layer of VB. Not necessarily a bad thing - since the whole point
of VB is to provide a language emphasizing descriptiveness, not conciseness.
 
The ReadOnly keyword (along with many other keywords in VB, such as
WriteOnly, Overloads) *should* not be required by the compiler

Unless it's an abstract/MustInherit property.



Mattias
 
Back
Top