Default Property

  • Thread starter =?ISO-8859-1?Q?Bernard_Bour=E9e?=
  • Start date
?

=?ISO-8859-1?Q?Bernard_Bour=E9e?=

I would like to achieve the following goal: design a class with a
default property called dVal where I could store and get a decimal value
WITHOUT the need to write the property.

I have the following code:

Dim Var as New VarDécimal
Var = 100 (instead of Var.dVal)

But I get an error telling me that a default property need to have a
parameter ! Why and what for ?
How to solve my problem ?

Thanks for your help
Bernard

Public Class VarDécimal
Private mNomVar As String
Private mVal As Decimal
Public Property Nom() As String
Get
Return mNomVar
End Get
Set(ByVal Value As String)
mNomVar = Value
End Set
End Property
Default Public Property dVal() As Decimal
Get
Return mVal
End Get
Set(ByVal Value As Decimal)
mVal = Value
End Set
End Property

End Class
 
H

Herfried K. Wagner [MVP]

Bernard Bourée said:
I would like to achieve the following goal: design a class with a default
property called dVal where I could store and get a decimal value WITHOUT
the need to write the property.

I have the following code:

Dim Var as New VarDécimal
Var = 100 (instead of Var.dVal)

But I get an error telling me that a default property need to have a
parameter ! Why and what for ?
How to solve my problem ?

Default properties in .NET /must/ be parameterized to avoid ambiguity.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top