在class1里边做个静态属性: private static System.Collections.ArrayList list = new System.Collections.ArrayList(); public static System.Collections.ArrayList List { get { return Form1.list; } set { Form1.list = value; } } 在class2里边调用: Class1.List; for(int i=0;i<Class1.List.Count;i++) {}
private static System.Collections.ArrayList list = new System.Collections.ArrayList(); public static System.Collections.ArrayList List
{
get { return Form1.list; }
set { Form1.list = value; }
}
在class2里边调用:
Class1.List;
for(int i=0;i<Class1.List.Count;i++)
{}
要不就Class1 class=new Class1();
然后for(int i=0;i<class.list.count;i++)
在class2中
using System.Collections;
private static ArrayList arr = new ArrayList();
public static ArrayList Arr
{
get
{
return arr;
}
set
{
arr = value;
}
}
我在class1中Class2 classB=new Class2();实例后还是调用不了
for(int i=0;i<Class1.ListCount;i++)
{}
写成静态的话,那么这个Arr就属于类的。
建议你看下有关静态类、字段、属性、方法之类的资料。
ArrayList o_ArrayList_1=new ArrayList();
//记录存放数据
string strBATCH_NO =" ";
for(int i=0;i <10;i++)
{
strBATCH_NO=i.ToString();
//将数据Add进数组1
o_ArrayList_1.Add(strBATCH_NO);
}
//调用delete方法删除,这里传递数组1
bool DEL=this.Delete(o_ArrayList_1);
//定义第二个数组
ArrayList o_ArrayList_2=new ArrayList(); //delete方法的参数要声明为ArrayList
public bool Delete(ArrayList o_aBatchNoList)
{
foreach(string s_BatchNo in o_aBatchNoList)
{
//将第一个数组添加进第二个数组
o_ArrayList_2.add(s_BatchNo);
}
}
public static ArrayList myarraylist=new ArrayList ();
class2中调用:
class1.myarraylist