/*
Author: Jiangong SUN
*/
public class CompareValueTypeAndReferenceType
{
public class ReferenceClass
{
public string Value { get; set; }
}
public struct Structure
{
public string Value { get; set; }
}
public static void Main()
{
ReferenceClass ref1 = new ReferenceClass();
ref1.Value = "ref1";
ReferenceClass ref2 = new ReferenceClass();
ref2.Value = "ref2";
ref2 = ref1;
Console.WriteLine(ref1.Value);
Console.WriteLine(ref2.Value);
ref2.Value = "ref3";
Console.WriteLine(ref1.Value);
Console.WriteLine(ref2.Value);
Structure struct1 = new Structure();
struct1.Value = "struct1";
Structure struct2 = new Structure();
struct2.Value = "struct2";
struct2 = struct1;
Console.WriteLine(struct1.Value);
Console.WriteLine(struct2.Value);
struct2.Value = "struct3";
Console.WriteLine(struct1.Value);
Console.WriteLine(struct2.Value);
Console.ReadLine();
}
}
Results:
References:
http://csharp-station.com/Tutorial/CSharp/Lesson22