且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我可以访问内部类中的外部类对象吗

更新时间:2023-02-15 16:32:13

如果我没看错,你想在 innerC 中访问类 A 的 objB 属性而不传递它.

If I'm reading you correctly you want to access the objB property of class A within innerC WITHOUT passing it along.

这不是 C# 内部类的工作方式,如本文所述:C# 嵌套类就像 C++ 嵌套类,而不是 Java 内部类

This isn't how C# inner classes work, as described in this article: C# nested classes are like C++ nested classes, not Java inner classes

如果您想从 innerC 访问 A.objB,那么您将不得不以某种方式将 A 类传递给 innerC.

If you want to access A.objB from innerC then you are going to have to somehow pass class A to innerC.