Created
July 30, 2018 11:07
-
-
Save yuchiki/95fd010277dd710456c529d8ceb7a715 to your computer and use it in GitHub Desktop.
comparison between value and reference in csharp
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
Java | |
------------ | |
Java | |
------------ | |
Perl | |
------------ | |
Perl | |
Ruby | |
------------ | |
Perl | |
Ruby | |
Python | |
------------ |
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; | |
using System.Collections.Generic; | |
using static System.Console; | |
class Test { | |
public static void Main(string[] args) { | |
var list = new List<string>(); | |
list.Add("Java"); | |
Show(list); | |
AddPHP(list); | |
Show(list); | |
AddPerl(ref list); | |
Show(list); | |
AddRuby(list); | |
Show(list); | |
AddPython(ref list); | |
Show(list); | |
} | |
static void AddPHP(List<String> list) { | |
list = new List<string>(); | |
list.Add("PHP"); | |
} | |
static void AddPerl(ref List<String> list) { | |
list = new List<string>(); | |
list.Add("Perl"); | |
} | |
static void AddRuby(List<String> list) => list.Add("Ruby"); | |
static void AddPython(ref List<String> list) => list.Add("Python"); | |
static void Show(IEnumerable<string> ss) { | |
foreach (var s in ss) WriteLine(s); | |
WriteLine("------------"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment