Skip to content

Instantly share code, notes, and snippets.

@yuchiki
Created July 30, 2018 11:07
Show Gist options
  • Save yuchiki/95fd010277dd710456c529d8ceb7a715 to your computer and use it in GitHub Desktop.
Save yuchiki/95fd010277dd710456c529d8ceb7a715 to your computer and use it in GitHub Desktop.
comparison between value and reference in csharp
Java
------------
Java
------------
Perl
------------
Perl
Ruby
------------
Perl
Ruby
Python
------------
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