abstract class foo
{
public string myId {get;set;}
public string mystring {get;set;}
public foo3 my3rdFoo {get;set}
}
class foo2 : foo
{
public string myFavoriteFoo {get;set;}
}
class foo3:foo2
{
public string myName{get;set}
}
使用实例化
Foo3 myThirdFoo = new foo3();
string result = foo3.myName;
如果您想从 foo2 内部访问第三个 foo ,请使用此代码
abstract class foo
{
public string myId {get;set;}
public string mystring {get;set;}
public foo3 my3rdFoo {get;set}
}
class foo2 : foo
{
public foo3 myFavoriteFoo {get;set;}
}
class foo3
{
public string myName{get;set}
}
并使用如下
foo3 ThirdFoo = new foo3();
ThirdFoo.myName = "Something nice";
foo2 SecondFoo = new foo2(){myFavouriteFoo = ThirdFoo};
String Result = SecondFoo.myFavouriteFoo.myName;
另一种方法是
abstract class foo
{
public string myId {get;set;}
public string mystring {get;set;}
public foo3 my3rdFoo {get;set}
}
class foo2 : foo
{
public foo3 myFavoriteFoo {get;set;}
public foo2(string myName)
{
foo3 = new foo3();
foo3.myName = myName;
}
}
class foo3
{
public string myName{get;set}
}
然后使用
foo2 SecondFoo = new foo2("Something nice");
String Result = SecondFoo.myfavouritefoo.myName;