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

Property. Which one should I use?

P: n/a
Hello,

Is there a difference between defining a control property in the
following two ways:

' Items ...
Private _Items As Generic.List(Of ListItem) = New Generic.List(Of
ListItem) ****
Property Items() As Generic.List(Of ListItem)
Get
Return _Items
End Get
Set(ByVal value As Generic.List(Of ListItem))
_Items = value
End Set
End Property ' Items

Or

' Items ...
Private _Items As Generic.List(Of ListItem) ****
Property Items() As Generic.List(Of ListItem)
Get
If _Items Is Nothing Then
****
_Items = New Generic.List(Of WebControl) ****
End
If ****
Return _Items
End Get
Set(ByVal value As Generic.List(Of ListItem))
_Items = value
End Set
End Property ' Items

I marked the differences with ****.

Which approach should I use?

Thanks,
Miguel

May 30 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
KJ
Why declare it as ListItem, then assign as WebControl?

"shapper" <md*****@gmail.comwrote in message
news:11**********************@q69g2000hsb.googlegr oups.com...
Hello,

Is there a difference between defining a control property in the
following two ways:

' Items ...
Private _Items As Generic.List(Of ListItem) = New Generic.List(Of
ListItem) ****
Property Items() As Generic.List(Of ListItem)
Get
Return _Items
End Get
Set(ByVal value As Generic.List(Of ListItem))
_Items = value
End Set
End Property ' Items

Or

' Items ...
Private _Items As Generic.List(Of ListItem) ****
Property Items() As Generic.List(Of ListItem)
Get
If _Items Is Nothing Then
****
_Items = New Generic.List(Of WebControl) ****
End
If ****
Return _Items
End Get
Set(ByVal value As Generic.List(Of ListItem))
_Items = value
End Set
End Property ' Items

I marked the differences with ****.

Which approach should I use?

Thanks,
Miguel

May 30 '07 #2

P: n/a
On May 30, 2:47 pm, "KJ" <n_o_s_p_a...@Mail.comwrote:
Why declare it as ListItem, then assign as WebControl?

"shapper" <mdmo...@gmail.comwrote in message

news:11**********************@q69g2000hsb.googlegr oups.com...
Hello,
Is there a difference between defining a control property in the
following two ways:
' Items ...
Private _Items As Generic.List(Of ListItem) = New Generic.List(Of
ListItem) ****
Property Items() As Generic.List(Of ListItem)
Get
Return _Items
End Get
Set(ByVal value As Generic.List(Of ListItem))
_Items = value
End Set
End Property ' Items
Or
' Items ...
Private _Items As Generic.List(Of ListItem) ****
Property Items() As Generic.List(Of ListItem)
Get
If _Items Is Nothing Then
****
_Items = New Generic.List(Of WebControl) ****
End
If ****
Return _Items
End Get
Set(ByVal value As Generic.List(Of ListItem))
_Items = value
End Set
End Property ' Items
I marked the differences with ****.
Which approach should I use?
Thanks,
Miguel
Sorry,

That was a type mistake.
My question is if I should declare a default value when I do "dim ..."

Or use an IF inside Get in property.

Thanks,
Miguel

May 30 '07 #3

P: n/a
KJ
Miguel,

At the very least, you should declare it and assign as Nothing.

In the property, you can assign the List to have a value if it's still
Nothing. That is fine; it's also known as "Lazy Instantiation"

On May 30, 1:21 pm, shapper <mdmo...@gmail.comwrote:
On May 30, 2:47 pm, "KJ" <n_o_s_p_a...@Mail.comwrote:
Why declare it as ListItem, then assign as WebControl?
"shapper" <mdmo...@gmail.comwrote in message
news:11**********************@q69g2000hsb.googlegr oups.com...
Hello,
Is there a difference between defining a control property in the
following two ways:
' Items ...
Private _Items As Generic.List(Of ListItem) = New Generic.List(Of
ListItem) ****
Property Items() As Generic.List(Of ListItem)
Get
Return _Items
End Get
Set(ByVal value As Generic.List(Of ListItem))
_Items = value
End Set
End Property ' Items
Or
' Items ...
Private _Items As Generic.List(Of ListItem) ****
Property Items() As Generic.List(Of ListItem)
Get
If _Items Is Nothing Then
****
_Items = New Generic.List(Of WebControl) ****
End
If ****
Return _Items
End Get
Set(ByVal value As Generic.List(Of ListItem))
_Items = value
End Set
End Property ' Items
I marked the differences with ****.
Which approach should I use?
Thanks,
Miguel

Sorry,

That was a type mistake.
My question is if I should declare a default value when I do "dim ..."

Or use an IF inside Get in property.

Thanks,
Miguel

May 31 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.