Created
February 12, 2012 04:37
-
-
Save sgkim126/1806379 to your computer and use it in GitHub Desktop.
C# Evaluation strategy
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.Collections.Generic; | |
class CallBy | |
{ | |
static void Main(string[] args) | |
{ | |
List<int> list ; | |
list = new List<int>(); | |
list.Add(0); | |
CallByReference(ref list); | |
Print("Call by Reference", list); | |
list = new List<int>(); | |
list.Add(0); | |
CallByReference2(ref list); | |
Print("Call by Reference2", list); | |
list = new List<int>(); | |
list.Add(0); | |
CallBySharing(list); | |
Print("Call by Sharing", list); | |
list = new List<int>(); | |
list.Add(0); | |
CallBySharing2(list); | |
Print("Call by Sharing2", list); | |
} | |
static void CallByReference(ref List<int> list) | |
{ | |
list.Add(1); | |
} | |
static void CallByReference2(ref List<int> list) | |
{ | |
list = new List<int>(); | |
list.Add(1); | |
} | |
static void CallBySharing(List<int> list) | |
{ | |
list.Add(1); | |
} | |
static void CallBySharing2(List<int> list) | |
{ | |
list = new List<int>(); | |
list.Add(1); | |
} | |
static void Print(string name, List<int> list) | |
{ | |
System.Console.WriteLine(name); | |
foreach (int element in list) | |
{ | |
System.Console.WriteLine(element); | |
} | |
} | |
} |
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
Call by Reference | |
0 | |
1 | |
Call by Reference2 | |
1 | |
Call by Sharing | |
0 | |
1 | |
Call by Sharing2 | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment