mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-18 12:31:22 +02:00
[CSharp/en]Added ref and out parameters
This commit is contained in:
@@ -380,6 +380,15 @@ on a new line! ""Wow!"", the masses cried";
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Methods can have the same name, as long as the signature is unique
|
||||||
|
// A method that differs only in return type is not unique
|
||||||
|
public static void MethodSignatures(
|
||||||
|
ref int maxCount, // Pass by reference
|
||||||
|
out int count)
|
||||||
|
{
|
||||||
|
count = 15; // out param must be assigned before control leaves the method
|
||||||
|
}
|
||||||
|
|
||||||
// Methods can have the same name, as long as the signature is unique
|
// Methods can have the same name, as long as the signature is unique
|
||||||
public static void MethodSignatures(string maxCount)
|
public static void MethodSignatures(string maxCount)
|
||||||
{
|
{
|
||||||
@@ -414,6 +423,10 @@ on a new line! ""Wow!"", the masses cried";
|
|||||||
MethodSignatures(3, 1, 3, "Some", "Extra", "Strings");
|
MethodSignatures(3, 1, 3, "Some", "Extra", "Strings");
|
||||||
MethodSignatures(3, another: 3); // explicity set a parameter, skipping optional ones
|
MethodSignatures(3, another: 3); // explicity set a parameter, skipping optional ones
|
||||||
|
|
||||||
|
// BY REF AND OUT PARAMETERS
|
||||||
|
int maxCount = 0, count; // ref params must have value
|
||||||
|
MethodSignatures(ref maxCount, out count);
|
||||||
|
|
||||||
// EXTENSION METHODS
|
// EXTENSION METHODS
|
||||||
int i = 3;
|
int i = 3;
|
||||||
i.Print(); // Defined below
|
i.Print(); // Defined below
|
||||||
|
Reference in New Issue
Block a user