【发布时间】:2015-06-12 13:58:49
【问题描述】:
我有一个简单的静态类,用于从应用程序的任何地方访问我的 AVLTree。但是由于某种原因,我无法从另一个类中调用该变量。每当我键入数据库时。我只得到两种不是我想要的方法。我想访问 Database.countries 但这是不可能的。
static class Database
{
static AVLTree<Country> countries = new AVLTree<Country>();
static Database()
{
}
static AVLTree<Country> cees()
{
return countries;
}
static AVLTree<Country> Countries
{
get { return countries; }
}
}
【问题讨论】:
-
如果你想从课堂外访问它们,你的属性应该是
public。 -
类成员的默认修饰符是
private,因此您需要添加public,例如public static AVLTree<Country> Countries.