【发布时间】:2010-11-09 03:47:34
【问题描述】:
我正在学习 C#,但遇到了这个问题:
namespace MyDataLayer
{
namespace Section1
{
public class MyClass
{
public class MyItem
{
public static string Property1{ get; set; }
}
public static MyItem GetItem()
{
MyItem theItem = new MyItem();
theItem.Property1 = "MyValue";
return theItem;
}
}
}
}
我在 UserControl 上有这段代码:
using MyDataLayer.Section1;
public class MyClass
{
protected void MyMethod
{
MyClass.MyItem oItem = new MyClass.MyItem();
oItem = MyClass.GetItem();
someLiteral.Text = oItem.Property1;
}
}
一切正常,除非我去访问Property1。智能感知只给我“Equals、GetHashCode、GetType 和ToString”作为选项。当我将鼠标悬停在oItem.Property1 上时,Visual Studio 给出了这样的解释:
MemberMyDataLayer.Section1.MyClass.MyItem.Property1.getcannot be accessed with an instance reference, qualify it with a type name instead
我不确定这意味着什么,我用谷歌搜索了一些但无法弄清楚。
【问题讨论】: