【发布时间】:2011-08-07 06:28:14
【问题描述】:
说我有
class temp {
private List<temp3> aList = new List<temp3>();
public List<temp3> getAList()
{
return this.aList;
}
public temp() {
}
}
class temp3 {
public temp3() {}
}
现在我有另一门课
class temp2 {
private temp t = new temp();
t.aList.Add(new temp3());
}
会
t.getAList.Add(new temp3());
真的将 temp3 添加到 temp 类的 aList 中吗?
【问题讨论】:
-
请重新表述您的问题? “真正添加到临时类中的 aList”是什么意思?请解释一下。
-
这里的“a”是什么意思...请更改“a”类的名称以澄清它..
-
我用 temp3 改写了 a
-
temp.aList是私有的,所以t.aList.Add不起作用!?为什么您认为temp3会不会被添加到列表中?是的,当然会,但在你的情况下,就像我说的那样,aList是私人成员,无法访问。 -
你也必须把语句放在一个方法中..你不能直接把它放在一个类中
标签: c# class list function reference