static ArrayList pArray = new ArrayList();
        static void Main(string[] args)
        {
                     
            Edge e = new Edge();
            e.From = "a";
            e.ID = "1";
            e.TO = "b";
            pArray.Add(e);
            testRefuse t = new testRefuse();
            
        }
        public class testRefuse
        {
            private ArrayList arrList = new ArrayList();
            public testRefuse()
            {
                arrList.AddRange(pArray);
                ((Edge)arrList[0]).From = "c";
                Console.WriteLine("arrlist中的元素有:");
               foreach(Edge tem in arrList)
                {
                    
                    Console.WriteLine("ID={0},From={1},To={2}",tem.ID,tem.From,tem.TO);
                }
                Console.WriteLine("pArray中的元素有:");
                foreach (Edge tem in pArray)
                {                    Console.WriteLine("ID={0},From={1},To={2}", tem.ID, tem.From, tem.TO);
                }
                
            }
           
        }
        public class Edge
        {
            public string ID;
            public string From;
            public string TO;
            
        }
要是这种情况又应该如何处理呢,我只是想改变arrList中的值,而不想改变pArray中的值。。即pArray中为Edge(1,a,b),而arrList中为(1,c,b)

解决方案 »

  1.   

    没好办法,重定义一个Edge给它
      

  2.   

    绕来绕去都是在一个edge对象里面((Edge)arrList[0]).From = "c";
      

  3.   

    你上面的代码在你的机子上能正确运行吗?
    我的不可以啊
    我帮你改了一下就可以了,也能实现你要的功能了 其实很简单啊
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Collections;namespace ConsoleApplication1
    {
        
       public  class Program
        {
            static ArrayList pArray = new ArrayList();
         
            static void Main(string[] args)
            {
                        Edge e = new Edge();
                e.From = "a";
                e.ID = "1";
                e.TO = "b";
                pArray.Add(e);
                testRefuse t = new testRefuse(pArray);
                
            }
        }        public class testRefuse
            {
               
                private ArrayList arrList = new ArrayList();
                public testRefuse(ArrayList list)
                {
                    
                    Console.WriteLine("pArray中的元素有:");
                   
                    foreach (Edge tem in list)
                    {                    Console.WriteLine("ID={0},From={1},To={2}", tem.ID, tem.From, tem.TO);
                    }
                    arrList.AddRange(list);
                    ((Edge)arrList[0]).From = "c";
                    Console.WriteLine("arrlist中的元素有:");
                   foreach(Edge tem in arrList)
                    {
                        
                        Console.WriteLine("ID={0},From={1},To={2}",tem.ID,tem.From,tem.TO);
                    }
                }
               
            }
            public class Edge
            {
                public string ID;
                public string From;
                public string TO;
                
            }}
      

  4.   

    我只是想实现这个功能而已,并不是为了打出来。
    其实我是最终目的是利用A*算法实现最短路径的。在初始化道路网络时,用的时ArrayList来存放路网信息的。但查找完后,就改变了ArrayList里面的一些信息。。想回到原始状态时,找不到方法
      

  5.   

    试过没有成功,对引用类型的数据处理时小心,最好重新new