我有三个这样的课程.
class A
{
public class innerB
{
//Do something
}
public class innerC
{
//trying to access objB here directly or indirectly over here.
//I dont have to create an object of innerB, but to access the object created by A
//i.e.
innerB objInnerB = objB;
//not like this
innerB objInnerB= new innerB();
}
private innerB objB{get;set;} **//Private**
public A()
{
objB= new innerB();
}
}
我想访问由 A 类创建的 C 类中 B 类的对象.是否有可能以某种方式对 C 类中 A 类的对象进行更改.我可以通过创建事件或任何方式来获取 A 类的对象吗?
I want to access the object of class B in Class C that is created by class A. Is it possible somehow to make changes on object of Class A in Class C. Can i get Class A's object by creating event or anyhow.
我提出上述问题的错误.在 A 中创建的 B 的对象是私有的而不是公共的
是否可以通过创建事件来做到这一点
IS IT POSSIBLE TO DO THIS BY CREATING EVENT
如果我能够引发一个 A 类可以处理的事件,那么我的问题就可以解决了.
If anyhow I become able to raise an event that can be handled by Class A, then my problem can be solved.
如果我没看错,你想在 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.
这篇关于我可以访问内部类中的外部类对象吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!