In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what is the usage of the this keyword of C#". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the usage of the this keyword of C#"?
In the process of using C #, it is found that the key to this is relatively rare, but it must be used in the following three situations, and it will not solve the problem without using it.
The first situation is when the name of the class member variable is the same as the parameter name of the function.
For example, this is the case:
Public class Employee {private string alias; private string name; public Employee (string name, string alias) {/ / Use this to qualify the members of the class / / instead of the constructor parameters. This.name = name; this.alias = alias;}}
Here you can see that the name of the class member variable is alias, and the name of the constructor is also alias. If the compiler wants to distinguish which name is, it needs to add a this pointer to the member variable in the class, which can indicate that the name of the reference comes from the class, not from the parameters of the function, so as to achieve the purpose of distinction. In many cases, you can write different names of members in the function, so you don't have to deal with it this way.
The second situation is to pass the current object as an argument to another function.
CalcTax (this)
The modulation function CalcTax is within a class function, so if you want to pass it to others, you can only use a this reference, only it is a variable used to mark yourself.
Class Employee {private string name; private string alias; private Thank you for your reading, the above is the content of "what is the usage of the this keyword of C#". After the study of this article, I believe you have a deeper understanding of the usage of the this keyword of C#, and the specific use still needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.