什么是'this'关键字? [英] what is 'this' keyword for?

查看:92
本文介绍了什么是'this'关键字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个''''的关键词是什么?如果我正在填写一个文本框,那么

之间的区别是什么?b $ b this.textbox1.Text =" my text" ;;和textbox1.Text =" my text" ;; ?

我通常使用它而没有这个。

谢谢。

What is the ''this'' keyeword for? If I''m filling a textbox, what''s the
difference between
this.textbox1.Text = "my text"; and textbox1.Text = "my text"; ?
I normally use it w/o the ''this''.
Thanks.

推荐答案

当您在类的方法或属性中编写代码时,使用this

将允许您使用intellisense。

我猜这在Winform应用程序中特别有用。有很多

属性/方法可供使用...


appart来自你所提到的情况,没有差异。完全没有

$ b $bJosé


" vaughn" < VM> écritdansle message de

news:uC ************** @ TK2MSFTNGP12.phx.gbl ...
When you are writting code in method or property of a class, using "this"
will allow you to make use of the intellisense.
I guess this is particulary usefull in Winform apps. There are so many
properties/methods to use...

appart from that in the situation you mentioned, there is no diff. at all

José

"vaughn" <VM> a écrit dans le message de
news:uC**************@TK2MSFTNGP12.phx.gbl...
什么是''this''的关键词是?如果我正在填写一个文本框,
this.textbox1.Text =" my text" ;;
之间的区别是什么?和textbox1.Text =" my text" ;; ?
我通常使用它而没有这个。
谢谢。
What is the ''this'' keyeword for? If I''m filling a textbox, what''s the
difference between
this.textbox1.Text = "my text"; and textbox1.Text = "my text"; ?
I normally use it w/o the ''this''.
Thanks.



"这"表示您所在的当前对象的实例。

假设您有:

类测试{

TextBox t1 = new TextBox ();

public void Method(){

TextBox t1 = new TextBox();

this.t1.Text =" blah" ;; //调用属于

类的文本框。

t1.Text =" blah2" ;; //调用属于该方法的文本框。

//两个文本框完全不同,并且它们彼此没有任何关系。一个具有更广泛的范围(第一个定义的是
),而第二个范围仅限于

方法//Method()

}

}

" vaughn" < VM>在消息新闻中写道:uC ************** @ TK2MSFTNGP12.phx.gbl ...
"this" represents the instance of the current object you are on.
Lets say that you have a:
class Test{
TextBox t1 = new TextBox();
public void Method(){
TextBox t1 = new TextBox();
this.t1.Text = "blah"; // calls the textbox that belongs to the
class.
t1.Text = "blah2"; // calls the textbox that belongs to the method.
//both textboxes are completely different, and they have nothing to
do //with each other. One has a broader scope (the one that is
defined //first) while the scope of the second one is limited to
the method //"Method()"
}
}
"vaughn" <VM> wrote in message news:uC**************@TK2MSFTNGP12.phx.gbl...
这个''''的关键词是什么?如果我正在填写一个文本框,
this.textbox1.Text =" my text" ;;
之间的区别是什么?和textbox1.Text =" my text" ;; ?
我通常使用它而没有''这个'。
谢谢。
What is the ''this'' keyeword for? If I''m filling a textbox, what''s the
difference between
this.textbox1.Text = "my text"; and textbox1.Text = "my text"; ?
I normally use it w/o the ''this''.
Thanks.



嗨vaughn ,

您可以使用或不使用* this *。使用* this *可能会使代码更清晰

并且在使用InetlliSense时会有所帮助。

当你有本地变量时,这* *是解决歧义的必要条件

并键入具有相同名称的成员。


HTH

B \ rgds

100


" vaughn" < VM>在消息新闻中写道:uC ************** @ TK2MSFTNGP12.phx.gbl ...
Hi vaughn,
You can used with or without *this*. Using *this* may make the code clearer
and it helps when use InetlliSense.
Hoever *this* is necesarry to solve ambiguities when you have local variable
and type member with the same name.

HTH
B\rgds
100

"vaughn" <VM> wrote in message news:uC**************@TK2MSFTNGP12.phx.gbl...
这个''''的关键词是什么?如果我正在填写一个文本框,
this.textbox1.Text =" my text" ;;
之间的区别是什么?和textbox1.Text =" my text" ;; ?
我通常使用它而没有''这个'。
谢谢。
What is the ''this'' keyeword for? If I''m filling a textbox, what''s the
difference between
this.textbox1.Text = "my text"; and textbox1.Text = "my text"; ?
I normally use it w/o the ''this''.
Thanks.



这篇关于什么是'this'关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆