我们可以在外部类的构造函数中创建内部类的对象到C#中吗?它合法吗?将内部类对象转换为C#的外部类构造函数#
public class Outer
{
public Inner InnerObj {get; set; }
public Outer()
{
Inner inner = new Inner();
}
public Outer(Inner inner)
{
InnerObj = inner;
}
public class Inner
{
}
}
为Java我把从参考以下链接: Can we create an object of the inner class in the constructor of the outer class?
我的同事说,这是不可能在C#中,它是完全非法的。请指导我。
接受一些答案... – MoonKnight 2012-04-25 07:58:22
你试过吧!? – 2012-04-25 08:06:02
你应该听听编译器,而不是听你的同事以及可能不是我们这样的小事。不难看出[它编译得很好](http://ideone.com/79YB9)。 – Jon 2012-04-25 08:07:38