Solved

Generic List<> as a property

Posted on 2009-05-08
7
2,056 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
7 Comments
 
LVL 8

Assisted Solution

by:OBonio
OBonio earned 250 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 250 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now