सी #, नेट 2.0इस प्रतिबिंब कोड के साथ क्या गलत है? GetFields() एक खाली सरणी लौटने
कोड यह (मैं अपने सभी डोमेन-विशिष्ट सामान बाहर ले लिया है, और यह अभी भी एक खाली सरणी देता है):
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
ChildClass cc = new ChildClass();
cc.OtherProperty = 1;
FieldInfo[] fi = cc.GetType().GetFields();
Console.WriteLine(fi.Length);
Console.ReadLine();
}
}
class BaseClass<T>
{
private int myVar;
public int MyProperty
{
get { return myVar; }
set { myVar = value; }
}
}
class ChildClass : BaseClass<ChildClass>
{
private int myVar;
public int OtherProperty
{
get { return myVar; }
set { myVar = value; }
}
}
}
+1 यह वह है, आपको * इंस्टेंस के साथ-साथ गैर-सार्वजनिक निर्दिष्ट करना होगा। –
उत्तर के लिए चीयर्स! हालांकि मुझे इसे समझने में परेशानी हो रही है। क्या कोई व्यक्ति कृपया बता सकता है कि निजी क्षेत्रों के लिए गैर-सार्वजनिक के साथ इंस्टेंस या स्टेटिक क्यों आवश्यक है? – Zack
@ rory.ap: हाँ, बिल्कुल। –