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)
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)
解决方案 »
- C#的ProgressBar能改装成显示电池电量吗
- 百度快照网址提取,正则表达式
- C#动态生成的button如何设置背景图片
- 正则表达式 的问题
- c# 用mcisendstring 播放mp3等文件的类
- C# mvc 在线付款接口返回时出现Object reference not set to an instance of an object.
- 真心急求!C#程序代码,读取另一台电脑上的txt文件数据
- C#子窗体获取父窗体自定义控件里的信息
- NET(C#)连接各类数据库-集锦(转)
- 求救,急
- SkinCrafter 中文 乱码
- 请教如何获取gridview里某一个单元格的值并传递到一个新的页面中
我的不可以啊
我帮你改了一下就可以了,也能实现你要的功能了 其实很简单啊
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;
}}
其实我是最终目的是利用A*算法实现最短路径的。在初始化道路网络时,用的时ArrayList来存放路网信息的。但查找完后,就改变了ArrayList里面的一些信息。。想回到原始状态时,找不到方法