【发布时间】:2012-04-18 12:34:45
【问题描述】:
在 File1 中,我创建了一个包含 3 个字符串的类。我用公共数组列表创建了另一个类。我希望这个数组列表是动态的,它包含的对象是具有 3 个字符串的类。 我可以在文件中访问类的成员,但不能在单独的文件中访问。
文件1
public class SensorCollection
{
public string ipAddress;
public string portNumber;
public string physicalLocation;
public DetectorCollection(string ipAddr, string portNum, string loc)
{
this.ipAddress = ipAddr;
this.portNumber = portNum;
this.physicalLocation = loc;
}
}
public class SensorCollectionArray
{
public System.Collections.ArrayList SensorArrayList;
}
...
System.Collections.ArrayList DetectorArrayList = new System.Collections.ArrayList();
...
DetectorArrayList.Add(new DetectorCollection(ipAddress, portNum, str));
所以我可以填充类数组,但不能在单独的文件中访问它。 文件 2
AdvancedSettingsForm.SensorCollectionArray mainDetectorCollectionArray;
System.Collections.ArrayList arrList;
【问题讨论】:
-
您的代码无法编译。你的构造函数是
DetectorCollection,但你的类是SensorCollection。 -
文件是否在同一个命名空间中?
-
您使用的是 .net 1.x 还是为什么使用
ArrayList而不是List<T>?