user3756594
user3756594

Reputation: 73

How can i check if a List<string> have been changed?

I have a List that every X seconds get update. I want to know each X seconds if a new item/s have been added to the List and what are the items.

For example i have in the List:

index 0 : this is a test
Index 1 : this is number one

Then after X seconds a new item have been added:

index 0 : this is a test
Index 1 : this is number one
Index 2 : Im a new item

What i want to do is to check for any new items it can be one item or 20 after X seconds and all this items should be add to the top of the List. So each time the last item will be the first. If only one item was added he will be the first if 20 items have been added then the item 20 will be the first in the List and item 1 of the 20 will be at number 20.

I asked before but now i know more what i need.

And just doing inser(0,...) is not good.

newText.Add(t[i]);
newText.Add(dateTime[i]);
newText.Add(string.Empty);

If im doing newText.Insert(0,t[i]); it dosent show anything later. If im using the Insert property it won't build the List as i wanted it will add the date&time all of them in the end and also the empty lines...

Thats why i didn't use Insert.

EDIT

I forgot to mention that i need to keep the List format:

newText.Add(t[i]);
newText.Add(dateTime[i]);
newText.Add(string.Empty);

When i mean last item i mean last 3 indexs. Each 3 indexs in the List are like one group/block. The List format is like this:

Index 0 text: hello world Index 1 date&time: 22/6/2014 Index 2 space/empty line:

So when i mean to move to the last item to the top of the List i mean that for exmaple index 28 will be at index 0 then index 29 at index 1 and index 30 at index 2. Since in index 28 i have a text index 29 date&time and index 30 empty line.

This is how the List look like:

enter image description here

Upvotes: 0

Views: 1968

Answers (1)

user287107
user287107

Reputation: 9417

how about using ObservableCollection<T>?

http://msdn.microsoft.com/library/ms668604(v=vs.110).aspx

with this you could monitor the list in real time.

what also would be possible, monitoring the CollectionChanged event and collect it in a second list, which you clear every 20 seconds

Upvotes: 2

Related Questions