mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 09:41:36 +00:00
[CSharp/en]Added ref and out parameters
This commit is contained in:
parent
69e38974ae
commit
04c4433433
@ -380,6 +380,15 @@ on a new line! ""Wow!"", the masses cried";
|
||||
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
|
||||
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, 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
|
||||
int i = 3;
|
||||
i.Print(); // Defined below
|
||||
|
Loading…
Reference in New Issue
Block a user