Property.

S

shapper

Hello,

On my profile I have a property as follows:

Private _Levels As Generic.List(Of Enumeration.Level)
Public Property Levels() As Generic.List(Of Enumeration.Level)
Get
If _Levels Is Nothing Then
Return New Generic.List(Of Enumeration.Level)
End If
Return _Levels
End Get
Set(ByVal value As Generic.List(Of Enumeration.Level))
_Levels = value
End Set
End Property ' Levels

When I create a new profile I don't add any items to this property ...
only later.
However when later I try to add items they are not added.

The only way to make this work is to, when I create the profile for
the new user, the following:
Profile.Levels = New Generic.List(Of Level)

Just like an initialization.

Well, do I really need to do that?
Maybe my property is not completely right ...

Should I change something in my property?

Thanks,
Miguel
 
G

Guest

shapper,

you need to correct your code to make it work:
Get
If _Levels Is Nothing Then
' in the next line change Return to _Levels =
_Levels = New Generic.List(Of Enumeration.Level)
End If
Return _Levels
End Get
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

shapper said:
Hello,

On my profile I have a property as follows:

Private _Levels As Generic.List(Of Enumeration.Level)
Public Property Levels() As Generic.List(Of Enumeration.Level)
Get
If _Levels Is Nothing Then
Return New Generic.List(Of Enumeration.Level)
End If
Return _Levels
End Get
Set(ByVal value As Generic.List(Of Enumeration.Level))
_Levels = value
End Set
End Property ' Levels

When I create a new profile I don't add any items to this property ...
only later.
However when later I try to add items they are not added.

Why do you think that they are not added? What have you done to come to
this conclusion?
 
G

Guest

Sergey said:
shapper,

you need to correct your code to make it work:
Get
If _Levels Is Nothing Then
' in the next line change Return to _Levels =
_Levels = New Generic.List(Of Enumeration.Level)
End If
Return _Levels
End Get

That doesn't have anything to do with the problem. It makes the property
return the same empty list instead of creating a new one every time if
the property is read multiple times before it's set, so it's not a bad
thing to do, but it's not relevant for the question.
 

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

Similar Threads


Top