什么是'this'关键字?

编程入门 行业动态 更新时间:2024-10-26 12:32:23
本文介绍了什么是'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'关键字?

本文发布于:2023-06-08 21:24:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/589311.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:关键字

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!