Search C # (Function 3) C # Talent Bird (QQ: 249178521)
8.Ref / OUT overload
· REF / OUT is part of the logo in most cases!
w You can overload an REF type parameter and a normal parameter
w You can overload an OUT type parameter and a normal parameter
w You can't overload a REF type parameter and an OUT type parameter
Sealed Class Overloading
{
Void ALLOWED (INT parameter)
{...}
Void ALOWED (Ref Int Parameter)
{...}
/ / Correct, overload an REF parameter and a normal parameter
Void alsoallowed (int parameter)
{...}
Void AlsoAllowed (Out Int Parameter)
{...}
/ / Correct, overload an OUT type parameter and a normal parameter
Void Notallowed (Ref Int Parameter)
{...}
Void Notallowed (Out Int Parameter)
{...}
// Error, can not be overloaded with a REF type parameter and an OUT type parameter
}
The REF and OUT modifiers can be a function of a function. But you can't overload the REF and OUT type parameters at the same time. The REF and OUT modifiers are "safe" in a sense because only REF type factors can be passed to the REF function parameters, and only OUT type factors can be passed to the OUT type function parameters. However, when calling a function, you will be very easy to forget the REF and OUT modifiers, so it is best not to overload the REF and OUT type parameters. E.g:
Sealed Class Overloading
{
Public Static Void Example (int parameter)
{...}
Public Static Void Example (Ref Int Parameter)
{...}
Static void
Main
()
{
INT Argument = 42;
Example (argument); // This is very easy here to forget the REF modifier
}
}
9. Access Rules
l Function parameter or return value cannot be lower than the access level of the function.
Sealed Class T {...} // The default access level of the class is Internal
Public Sealed Class Bad
{
Public Void Parameter (T T) // Error, the function's access level (public) is higher than the parameter
{...}
Public t return () // error, the function's access level (public) is higher than the return value
{...}
}
Public Sealed Class Good
{
Private Void Parameter (T T) // is correct, the function's access level (private) is lower than the parameter
{...}
Private T Return () // is correct, the access level of the function is lower than the return value
{...}
}
10. Looking for errors
Sealed Class Buggy
{
Void Defaulted (double d = 0.0) 1
{...
}
Void Readonly (Const Ref Wibble W) 2
{...
}
Ref int Returntype () 3
{...
}
Ref int fieldModifier; 4}
The first function of the first function is that the function in the C # cannot have default parameters.
The error of the second function is that the REF type parameter cannot be modified with const modifications because the REF type parameters may vary.
The error of the 3rd, 4 functions is: REF and OUT parameters can only be used for function parameters and arguments.
The function of the default parameter can be achieved by the function overloaded by function, the following is the implementation method:
Sealed Class Overload
{
Void default () {defaultargument (0.0);
Void Defaultargument (double d) {...}
}