From 04c4433433f313884fe38f126b24ff52b59f3af1 Mon Sep 17 00:00:00 2001 From: Laoujin Date: Sat, 31 Jan 2015 21:45:13 +0100 Subject: [PATCH] [CSharp/en]Added ref and out parameters --- csharp.html.markdown | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/csharp.html.markdown b/csharp.html.markdown index fceda4ff..8eda5356 100644 --- a/csharp.html.markdown +++ b/csharp.html.markdown @@ -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