Created
December 17, 2015 12:58
-
-
Save alpersilistre/a087513f3f526e307de2 to your computer and use it in GitHub Desktop.
C# Parameter Passing example.(out, ref, normal passing)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace TestProject | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
int nInt = 10; | |
string nString = "I am a nString"; | |
Console.WriteLine(nInt); | |
Console.WriteLine(nString); | |
NormalFunction(nInt, nString); | |
Console.WriteLine(nInt); | |
Console.WriteLine(nString); | |
Console.WriteLine("------"); | |
int oInt; | |
string oString; | |
//Console.WriteLine(oInt); | |
//Console.WriteLine(oString); | |
OutFunction(out oInt, out oString); | |
Console.WriteLine(oInt); | |
Console.WriteLine(oString); | |
Console.WriteLine("------"); | |
int rInt = 30; | |
String rString = "I am a rString"; | |
Console.WriteLine(rInt); | |
Console.WriteLine(rString); | |
RefFunction(ref rInt, ref rString); | |
Console.WriteLine(rInt); | |
Console.WriteLine(rString); | |
Console.ReadLine(); | |
} | |
static void NormalFunction(int i, string s) | |
{ | |
i = 100; | |
s = "I am a string from NormalFunction"; | |
} | |
static void OutFunction(out int i, out string s) | |
{ | |
i = 200; | |
s = "I am a string from OutFunction"; | |
} | |
static void RefFunction(ref int i, ref string s) | |
{ | |
i = 300; | |
s = "I am a string from RefFunction"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment