Created
February 1, 2013 13:16
-
-
Save hagbarddenstore/4691242 to your computer and use it in GitHub Desktop.
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
void Main() | |
{ | |
var a = new A(1); | |
var b = new B(2); | |
Console.WriteLine("Value of A: {0}", a.Value); | |
Console.WriteLine("Value of B: {0}", b.Value); | |
ChangeA(a); | |
Console.WriteLine("Value of A: {0}", a.Value); | |
ChangeARef(ref a); | |
Console.WriteLine("Value of A: {0}", a.Value); | |
ChangeAValue(a); | |
Console.WriteLine("Value of A: {0}", a.Value); | |
ChangeB(b); | |
Console.WriteLine("Value of B: {0}", b.Value); | |
ChangeBRef(ref b); | |
Console.WriteLine("Value of B: {0}", b.Value); | |
} | |
void ChangeA(A a) | |
{ | |
Console.WriteLine("ChangeA"); | |
a = new A(3); | |
} | |
void ChangeARef(ref A a) | |
{ | |
Console.WriteLine("ChangeARef"); | |
a = new A(4); | |
} | |
void ChangeAValue(A a) | |
{ | |
Console.WriteLine("ChangeAValue"); | |
a.Value = 5; | |
} | |
void ChangeB(B b) | |
{ | |
Console.WriteLine("ChangeB"); | |
b.Value = 6; | |
} | |
void ChangeBRef(ref B b) | |
{ | |
Console.WriteLine("ChangeBRef"); | |
b = new B(7); | |
} | |
class A | |
{ | |
public A(int value) | |
{ | |
Value = value; | |
} | |
public int Value { get; set; } | |
} | |
struct B | |
{ | |
public int Value; | |
public B(int value) | |
{ | |
Value = value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result when this program is run:
Value of A: 1
Value of B: 2
ChangeA
Value of A: 1
ChangeARef
Value of A: 4
ChangeAValue
Value of A: 5
ChangeB
Value of B: 2
ChangeBRef
Value of B: 7