简体   繁体   English

C#相当于Java Class.this

[英]C# equivalent of Java Class.this

Question : What can be the C# equivalent of Java Class.this ? 问题:什么可以是Java Class.thisC#等价物?

Why : Suppose I've same class Form1 in both Java and C# . 原因:假设我在JavaC#中都有相同的Form1类。 In Java we can write Form1.this , how this can be written in C# . Java中我们可以编写Form1.this ,它是如何用C#编写的。

There is no equivalent, C# has no nested class support where it also tracks outer instances. 没有等价物,C#没有嵌套类支持,它也跟踪外部实例。 If needed you pass a pointer yourself and store it in a field/property. 如果需要,您自己传递指针并将其存储在字段/属性中。

If all you want is the normal this to reference members in the same instance, simply use the this keyword. 如果你想要的是正常this引用成员在同一个实例,简单地使用this关键字。 Or even better, don't -- it's implied. 或者甚至更好,不要 - 这是隐含的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM