List<int> date = new List<int>();
            date.Add(1);
            List<int> temp = date.GetRange(0, 1);
            temp[0] = 2;
上面的代码不能改变date[0]的值。GetRange是返回浅表副本,但是应该因为int是值类型,结果返回的就是一个副本了。
我想返回浅表副本怎么办呢

解决方案 »

  1.   

    http://topic.csdn.net/u/20120415/01/ee51f4eb-eaed-43f0-95f2-6dc5e7b70540.html或者使用如下代码:
    class SubList<T>
    {
        private List<T> innerList { get; set; }
        private int offset { get; set; }
        public SubList(List<T> list, int startindex) { innerList = list; offset = startindex; }
        public T this[int index] { get { return innerList[index + startindex]; } set { innerList[index + startindex] = value; } }
    }
    ...List<int> date = new List<int>();
    date.Add(1);
    SubList<int> temp = new SubList<int>(date, 0);
    temp[0] = 2;
      

  2.   

    自己实现一个sublist确实可以解决这个问题
    不过工作量 还是有点大吧。还有很多方法需要实现