在.NET中的静态方法,为什么你不能使用关键字'这个'? [英] Why can't you use the keyword 'this' in a static method in .Net?
本文介绍了在.NET中的静态方法,为什么你不能使用关键字'这个'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图使用这
关键字在静态方法,但是编译器不会允许我使用它。
I'm trying to use the this
keyword in a static method, but the compiler won't allow me to use it.
为什么不呢?
推荐答案
这是一个很容易的。关键字这个'返回对包含它的类的当前实例。静态方法(或任何静态成员)不属于一个特定的实例。它们的存在,而无需创建类的实例。有一个在什么静态成员深入解释更加,为什么/时使用他们在MSDN文档。
That's an easy one. The keyword 'this' returns a reference to the current instance of the class containing it. Static methods (or any static member) do not belong to a particular instance. They exist without creating an instance of the class. There is a much more in depth explanation of what static members are and why/when to use them in the MSDN docs.
这篇关于在.NET中的静态方法,为什么你不能使用关键字'这个'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文