?
Solved

Generic List<> as a property

Posted on 2009-05-08
7
Medium Priority
?
2,063 Views
Last Modified: 2012-05-06
I have a Type List<string>. How would I call the clear method on the List if it was a property.
This is how my property looks
List<string> _RecieveData = new List<string>();//Data Returned from the clock
        public List<string> RecieveData
        {
            get
            {
                return _RecieveData;
            }
            set
            {
                _RecieveData.Clear();
            }
        }

Open in new window

0
Comment
Question by:u2envy1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 8

Assisted Solution

by:OBonio
OBonio earned 1000 total points
ID: 24334745

<object>.ReceiveData.Clear()

Open in new window

0
 

Accepted Solution

by:
u2envy1 earned 0 total points
ID: 24334815
Thx.....
Are Generics Ref types or Value types ?
0
 
LVL 1

Expert Comment

by:Acumentality
ID: 24334822
If you want to use the setter to clear, you could use RecieveData = null; Your set method would then ignore the nulll (because you haven't used value). But I don't know why you would do it like that, that's just confusing.

RecieveData.clear() is more clear.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:u2envy1
ID: 24334881
If I assign another List<string> MyList = RecieveDate;
Then run  RecieveData.clear()
The MyList is also Cleared. Due to Reference types.
How do I not clear MyList when clearing RecieveDate ?
0
 
LVL 1

Expert Comment

by:Acumentality
ID: 24334918
They both refer to the same object. If you clear one, you clear both.
You'd have to create another list. If you want to copy the elements from recievedata to that list at the same time, use:
List<String> myList = new List<String>(RecieveData);

Open in new window

0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 1000 total points
ID: 24334933
Have you tried changing your get to:
get
{
    return new List<string>(_RecieveData);
}

Open in new window

0
 

Author Comment

by:u2envy1
ID: 24335021
Thanks this works......
get
{
    return new List<string>(_RecieveData);
}

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month13 days, 23 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question