By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,376 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

Default Property

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Bernard Bourée" <be*****@bouree.net> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.