Class A
{
//...
}
ArrayList arr = new ArrayList();
A a1 = new A();
arr.Add(a1);
A a2 = new A();
arr.Add(a2);
8 个解决方案
#1
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.Reflection;
using System.Collections;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.IO;
using System.Globalization;
using System.Threading;
using System.Data.OleDb;
using System.Data;
using SpeechLib;
namespace ConsoleApplication1
{
class A
{
public int ab=0;
}
class Test
{
static void Main()
{
ArrayList arr = new ArrayList();
A a = new A();
arr.Add(a);
Console.WriteLine(a.ab);
Console.WriteLine((arr[0] as A).ab);
a.ab = 1;
Console.WriteLine(a.ab);
Console.WriteLine((arr[0] as A).ab);
}
}
}
0
0
1
1
请按任意键继续. . .
这样看应该是用一个实例
#2
static void Main()
{
ArrayList arr = new ArrayList();
A a = new A();
arr.Add(a);
Console.WriteLine(a.ab);
Console.WriteLine((arr[0] as A).ab);
a.ab = 1;
Console.WriteLine(a.ab);
Console.WriteLine((arr[0] as A).ab);
a.ab++;
Console.WriteLine(a.ab);
Console.WriteLine((arr[0] as A).ab);
}
0
0
1
1
2
2
请按任意键继续. . .
#3
应该是引用!
#4
只是引用,不存在深浅拷贝~
#5
ArrayList arr = new ArrayList();
arr.Add(1);
arr.Add(arr);
((ArrayList)arr[1]).Add(2);
arr.RemoveAt(1);
foreach (int i in arr)
MessageBox.Show(i.ToString());
LZ猜猜看输出是啥?
#6
调式时可以查看究竟呢?
#7
Class A 没有实现IClone接口,不会是深拷贝。不过如果你实现IClone接口,也可以是浅拷贝,看你怎么实现Clone()。
#8
是引用地址.不存在copy 问题.
#1
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.Reflection;
using System.Collections;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.IO;
using System.Globalization;
using System.Threading;
using System.Data.OleDb;
using System.Data;
using SpeechLib;
namespace ConsoleApplication1
{
class A
{
public int ab=0;
}
class Test
{
static void Main()
{
ArrayList arr = new ArrayList();
A a = new A();
arr.Add(a);
Console.WriteLine(a.ab);
Console.WriteLine((arr[0] as A).ab);
a.ab = 1;
Console.WriteLine(a.ab);
Console.WriteLine((arr[0] as A).ab);
}
}
}
0
0
1
1
请按任意键继续. . .
这样看应该是用一个实例
#2
static void Main()
{
ArrayList arr = new ArrayList();
A a = new A();
arr.Add(a);
Console.WriteLine(a.ab);
Console.WriteLine((arr[0] as A).ab);
a.ab = 1;
Console.WriteLine(a.ab);
Console.WriteLine((arr[0] as A).ab);
a.ab++;
Console.WriteLine(a.ab);
Console.WriteLine((arr[0] as A).ab);
}
0
0
1
1
2
2
请按任意键继续. . .
#3
应该是引用!
#4
只是引用,不存在深浅拷贝~
#5
ArrayList arr = new ArrayList();
arr.Add(1);
arr.Add(arr);
((ArrayList)arr[1]).Add(2);
arr.RemoveAt(1);
foreach (int i in arr)
MessageBox.Show(i.ToString());
LZ猜猜看输出是啥?
#6
调式时可以查看究竟呢?
#7
Class A 没有实现IClone接口,不会是深拷贝。不过如果你实现IClone接口,也可以是浅拷贝,看你怎么实现Clone()。
#8
是引用地址.不存在copy 问题.