Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / May 2007

Tip: Looking for answers? Try searching our database.

Property. Which one should I use?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
shapper - 30 May 2007 13:47 GMT
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
KJ - 30 May 2007 14:47 GMT
Why declare it as ListItem, then assign as WebControl?

> Hello,
>
[quoted text clipped - 37 lines]
> Thanks,
> Miguel
shapper - 30 May 2007 18:21 GMT
> Why declare it as ListItem, then assign as WebControl?
>
[quoted text clipped - 39 lines]
> > 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
KJ - 31 May 2007 16:48 GMT
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"

> > Why declare it as ListItem, then assign as WebControl?
>
[quoted text clipped - 53 lines]
> Thanks,
> Miguel

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.