당신은 나에의 참조를 전달해야 할 것은
이 작업을 수행 할 수
한 가지 방법이다 중첩 클래스, 아래 예제를 참조하십시오.
namespace Example
{
class A
{
string Name = "test"; // access restricted only to this class
public string Type; // global access
internal string Access; // within defining namespace
protected string Code; // this class and subclass
// When you create a nested class like C, you can create instances of C within this class(A).
C c = new C();
class C
{
string name;
public C()
{
//this is a nested class and you cannot call A as its base
name = "test success";
}
}
}
class B : A
{
public string Type { get { return base.Type; } set { base.Type = value; } } // You can use base when you hide a base class member
public B()
{
Type = "test";
Code = "nothing";
Access = "success";
//Cannot Access 'Name' Here as it is private
}
}
}
Java에서이 예제를 사용하면 A.this.test 또는 A.this.hello()를 사용할 수 있지만 C#에서는 어떻게 할 수 있습니까? A에서 B 로의 참조를 전달하는 것 이외에? – Jasper
어떻게 할 수 있습니까? 클래스 B의 인스턴스에서 클래스 A의 인스턴스를 얻지 못했습니다. – Carsten