In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-25 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.