Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Asp.Net Programming

Property. Which one should I use?


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

Why declare it as ListItem, then assign as WebControl?

"shapper" <mdmo@gmail.com> wrote in message

news:1180529235.352842.248280@q69g2000hsb.googlegroups.com...

On May 30, 2:47 pm, "KJ" <n_o_s_p_a@Mail.com> wrote:

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

-----------------------------------------------Reply-----------------------------------------------

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.com> wrote:

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc