views:

61

answers:

2

i have the following property declaration

 Public Property IsAreaSelected() As Integer
        Get
            Return If(ViewState("IsAreaSelected") Is Nothing, 0, Cint(ViewState("IsAreaSelected")))
        End Get
        Set(ByVal value As Integer)
            ViewState("IsAreaSelected") = value
        End Set
    End Property

i want to know when this set and get method will be called ?

will it be called when i execute

IsAreaSelected() =0 

or is there anything like

IsAreaSelected().get()

or

IsAreaSelected().set()

??

A: 

You call (use) it exactly like a field in your class:

IsAreaSelected = 0 

If AreaSelected > 0 Then ...
Henk Holterman
field name is IsAreaSelected() not IsAreaSelected
Try using it like I wrote. My sample code executes both the Set and the Get. Otherwise, state your problem better.
Henk Holterman
A: 

Properties are referenced without using parentheses. To reference the property getter, use this syntax:

xxx = AreaSelected

To access the property setter, use this syntax:

AreaSelected = xxx
Prutswonder
in this case will the parenthesis will also been taken as a propertyname?
No. Parentheses are only used on methods, that's how you can distinguish them from each other. Unfortunately, VB.Net supports writing parameterless methods without parentheses, but it is considered good practise to include the parentheses.On the other hand, properties with parameters are also supported, and in that case, you also need to use parentheses. But you should avoid using parameterized properties and use methods instead.
Prutswonder