In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail what you should pay attention to about the methods in .NET. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
The specific analysis is as follows:
1. The return in the method terminates the entire method segment.
Break can only terminate the current loop.
two。 Method is the reuse of a pair of available code.
A. For reusable code, select in vs, right-click the refactoring extraction method. It can be automatically encapsulated into a method.
B. In programming, when we call an undefined method. Ctrl +. And then Enter. The corresponding method is automatically generated.
3. For method return values, if a return value is defined, there must be a corresponding return in the method.
If there is no return worth it, you can use void
4. The constructor does not need to be modified with keywords such as void or int.
5. The parameter modifier params represents a variable length parameter
Note: the variable parameter must be the last parameter!
Principle: when compiling, the compiler turns our actual parameters into an array. And pass it on. Personally, I think it's also grammatical candy. Ha ha
6. Parameter modifier ref
Represents reference passing. For the value type of the assignment reference, if you want to use the reference passing method to call the method. The method parameters need to be modified with ref.
Note:
1) the parameter must be assigned before it is referenced.
2) in the method, the ref parameter may not be assigned a value. (note that you don't have to do it, which means you can assign or not assign a value. )
For example, the method requires the exchange of the values of two variables.
Then you need to define it like this.
Public static void Swap (ref int a, ref int b) {/ / implements ellipsis. }
When calling
Int a = 1; / / int b = 2; / / Note that the value must be assigned in advance. Swap (ref a, ref b)
7. Parameter modifier out
Let the function output multiple values
Note:
1) the out parameter must be assigned a value in the method.
2) the variable of the out parameter does not need to be assigned before it is passed. (meaningless)
8. Method overload (overload) compile-time polymorphism
A method with the same name but different parameters is called method overloading.
Note:
Conditions for method overloading
1) the method name is the same
2) the number of parameters is different
Or
3) the number of parameters is the same but the type of parameters is different.
Compile-time polymorphism is static, although it is also called XX polymorphism, but it has nothing to do with object-oriented features.
Overloading is only a language feature, a grammatical rule, independent of polymorphism and object-oriented.
This is the end of this article on "what are the precautions for methods in .NET". I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, please share it for more people to see.
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.