'<yöntem üyesi&;' olamaz örnek bir başvuru ile erişilebilir gt
C girmesini ben# ve bu sorunu yaşıyorum:
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;
}
}
}
}
İçsel üzerinde bu kod var:
using MyDataLayer.Section1;
public class MyClass
{
protected void MyMethod
{
MyClass.MyItem oItem = new MyClass.MyItem();
oItem = MyClass.GetItem();
someLiteral.Text = oItem.Property1;
}
}
Her ÅŸey iyi, Property1
erişim için gittiğimde dışında çalışır. Intellisense sadece bana"Equals
, GetHashCode
, GetType
, ve ToString
" seçenekleri olarak verir. Ben ** 10, Visual Studio üzerinde fare ne zaman bana verir bu açıklaması:
Member
MyDataLayer.Section1.Sınıfım.Myİtem.Özellik1.cannot be accessed with an instance reference, qualify it with a type name instead
Bunun ne anlama geldiğini emin değilim, biraz googling yaptım ama bulmak mümkün değildi.
CEVAP
C#, VB.NET ve Java aksine, örnek sözdizimi ile static
üyeleri erişebilir. Yapmanız gereken:
MyClass.MyItem.Property1
bu özellik bakın veya Property1
static
değiştirici muhtemelen yapmak istediğim şeydir) kaldırmak. static
is, see my other answer hakkında kavramsal bir fikir için.
Olamaz Statik Statik Olmayan Yöntem iç...
Olamaz bir iç sınıf içinde nihai olmay...
Başvuru javadoc yöntem bir parametre...
ASP.NET Bu yöntem olamaz uygulama sıra...
Neden yok C# statik bir yöntem bir örn...