I'm after an efficient way of detecting whether a List object has changed from one frame to the next.

List<int> intList = new List<int>();

I have my list as a member variable and will check to see if it has changed each Update() method call.

The only way I can think of is checking each element in the list to see if it has been changed/removed/added. This doesn't seem ideal?

Try setting a boolean variabke , isChanged to true in the block.

//Declare the bool var
if( condition)
isChanged = true;//

After this, you only need to check the list for the changes only if the isChanged = true;
Otherwise skip running the test/check unnecessarily.

This is simple solution... but hope it helps you.

Edited 5 Years Ago by ArathySharath: had not completed typing

This won't work in my case unfortunately but you weren't to know that.

My list is changed by a method in which I have no access to the code.

Sharath is right. Since you can't do as the first reply suggested, create an "old" copy before passing it to the method you cant access and then compare once getting it back.

Please read these articles:

1. http://www.codeproject.com/KB/cs/EventyList.aspx
2. http://damieng.com/blog/2006/06/14/observing_change_events_on_a_listt
3. http://msdn.microsoft.com/en-us/library/dd783449.aspx

1) It would seem that I can't convert from the generic List to EventyList, does EventyList not implement IList? Why is this the case?

Cannot convert from 'Prototype1.EventyList<int>' to 'System.Collections.Generic.List<int>'

2) The same problem as 1) and it also inherits from IList

3) I don't think that is available in Framework 3.5 which I am stuck with for the time being.

Is it possible to overcome the difficulties found with 1 and 2? I'm probably being thick.


Adding System.Collections.Generic.List<T> to the inheritance solves that problem but now nothing is added to the list in the called method (from which I can't access the code).

public class EventyList<T> : System.Collections.Generic.List<T>, IList<T>, System.Collections.IList

Edited 5 Years Ago by DaveTran: n/a

I didn't figure out the solution to this problem, sorry.

Edited 5 Years Ago by DaveTran: n/a

This article has been dead for over six months. Start a new discussion instead.