Skip to content

Instantly share code, notes, and snippets.

@alpersilistre
Created December 17, 2015 12:58
Show Gist options
  • Save alpersilistre/a087513f3f526e307de2 to your computer and use it in GitHub Desktop.
Save alpersilistre/a087513f3f526e307de2 to your computer and use it in GitHub Desktop.
C# Parameter Passing example.(out, ref, normal passing)
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