Generic List reference issue

May 5 2008 4:01 PM
This seems backwards to me, according to the logic that I've learned to code with.  I have a large amount of data that has to be used for a performance intensive windows form application.  The Data is stored - for a multitude of reasons -in an object that is basically a 5-layered generic list

The exact instantiation is

List<List<int[]>> xList = new List<List<int[]>>();

Now, if I want to create a shallow copy of this Generic List, I would have to use the GetRange method...I've tried this....I've done a lot of different things to achieve this shallow copy, but what ends up happening is any edits I make to the shallow copy are reflected in the original List as well.

here's an example of what I'm talking about:
   
             int[] x = new int[5] { 3, 5, 7, 9, 11 };

            List<int[]> tList = new List<int[]>();
            tList.Add(x);
            List<int[]> yList = new List<int[]>(tList.GetRange(0, tList.Count));



            yList[0][0] = 12; 

In this case, xList[0][0] Also gets changed to the value of 12.  Can anyone help me with this short of looping through the entire data list????

Answers (6)