1.When a parameter is passed to a method through an applicationThe called method obtains this variable, so any changes made to the variable within the method still play a role after the method exits.
2.When a parameter is passed to a method through a valueThe called method gets a copy of the variable, that is, after the method exits, modifications to the variable will be lost.
Note: strings are different, because strings cannot be changed (if the value of a string is changed, a new string will be created), so strings cannot adopt the common reference type. In method calls, any changes made to the string will not affect the original string.
3.Ref Parameter: If you pass a parameter to a method with the ref keyword before the input parameter of this method, any change made to the variable of this method will affect the value of the original object.
4.Out keyword: The out keyword is used for initialization. When the out keyword is added before the input parameter of the method, the variables passed to the method can not be initialized. This variable is passed through reference.
Ref indicates inbound and outbound, and out indicates outbound.
Using system;
Namespace consoleapplication3
{
Class Program
{
Static void somefunction (Out int I)
{
I = 100; // note how I is declared but not initialized
}
Static void main (string [] ARGs)
{
Int I;
Somefunction (Out I );
Console. writeline (I );
}
}
}
5.Method Overloading: The method name is the same, but the number and type of parameters are different.
For method overloading, if an incorrect method is called, a running error may occur:
- The two methods cannot be different only in the return type.
- The two methods cannot be distinguished only based on whether the parameter is declared as ref or out.