मैं अभिगम्यता पर शुरुआती सत्र के लिए कुछ डेमो कोड स्थापित कर रहा हूं और मैंने पाया कि मैं व्युत्पन्न कक्षा से आंतरिक संरक्षित संपत्ति तक पहुंचने में सक्षम हूं। मैं क्या खो रहा हूँ?आंतरिक संरक्षित संपत्ति अभी भी एक अलग असेंबली से सुलभ है
विधानसभा 1
namespace Accessibility
{
class Program
{
static void Main(string[] args)
{
ExampleClass c = new ExampleClass();
c.Go();
//c.Prop1 = 10;
}
}
class ExampleClass : DerivedClass
{
public void Go()
{
this.Prop1 = 10;
this.Prop2 = 10;
//this.Prop3 = 10; //Doesn't work
//this.Prop4 = 10; //Doesn't work
this.Prop5 = 10; //why does this work?!
this.DoSomething();
}
}
}
विधानसभा 2
namespace Accessibility.Models
{
public class BaseClass
{
public int Prop1 { get; set; }
protected int Prop2 { get; set; }
private int Prop3 { get; set; }
internal int Prop4 { get; set; }
internal protected int Prop5 { get; set; }
//internal public int Prop6 { get; set; } //Invalid
//internal private int Prop7 { get; set; } //Invalid
public BaseClass()
{
this.Prop3 = 27;
}
}
public class DerivedClass : BaseClass
{
public void DoSomething()
{
this.Prop1 = 10;
this.Prop2 = 10;
//this.Prop3 = 10; //Doesn't work
this.Prop4 = 10;
this.Prop5 = 10;
PropertyInfo Prop3pi = typeof(DerivedClass).GetProperty("Prop3", BindingFlags.Instance | BindingFlags.NonPublic);
int value = (int)Prop3pi.GetValue(this, null);
}
}
}
सूचना ExampleClass.Go में मैं Prop5 के लिए एक मूल्य निर्धारित कर सकते हैं। क्यूं कर? इसे आंतरिक संरक्षित के रूप में चिह्नित किया गया है लेकिन मैं प्रोप 4 (आंतरिक के रूप में चिह्नित) पर एक मूल्य निर्धारित नहीं कर सकता
क्योंकि यह * आंतरिक * या * संरक्षित * है। नहीं और। –
-1: जाहिर है, एक साधारण Google खोज ने इस प्रश्न का उत्तर दिया होगा ... –
मुझे नहीं लगता था कि यह या तो –