[CSharp/en]Added ref and out parameters

This commit is contained in:
Laoujin 2015-01-31 21:45:13 +01:00
parent 69e38974ae
commit 04c4433433

View File

@ -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