Skip to content

Instantly share code, notes, and snippets.

@zzandy
Last active October 30, 2018 12:07
Show Gist options
  • Save zzandy/3ff62bea1e5111136b6ac9459b988243 to your computer and use it in GitHub Desktop.
Save zzandy/3ff62bea1e5111136b6ac9459b988243 to your computer and use it in GitHub Desktop.
public struct Struct { public int Prop { get; set; } }
public class Class { public int Prop { get; set; } }
public static Class Change(Class cls) { cls.Prop = 1; return cls; }
public static Struct Change(Struct str) { str.Prop = 1; return str; }
...
var str = new Struct() { Prop = 2 };
var cls = new Class() { Prop = 2 };
var str2 = str;
var cls2 = cls;
str2.Prop = 3;
cls2.Prop = 3;
Console.WriteLine(str.Prop == str2.Prop);
Console.WriteLine(cls.Prop == cls2.Prop);
Console.WriteLine(str.Prop == Change(str).Prop);
Console.WriteLine(cls.Prop == Change(cls).Prop);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment