Created
March 17, 2014 11:12
-
-
Save RyuaNerin/9597518 to your computer and use it in GitHub Desktop.
Struct 와 Class 의 메모리 참조를 비교하는 파일
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.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace GITTEST | |
{ | |
class Program | |
{ | |
struct a | |
{ | |
public string aa; | |
} | |
class b | |
{ | |
public string aa; | |
} | |
static void Main(string[] args) | |
{ | |
List<a> lst = new List<a>(); | |
a st = new a(); | |
st.aa = "a"; | |
lst.Add(st); | |
Console.WriteLine("Struct"); | |
Console.WriteLine("Data : " + st.aa); | |
Console.WriteLine("List : " + lst[0].aa); | |
Console.WriteLine(); | |
st.aa = "b"; | |
Console.WriteLine("Data : " + st.aa); | |
Console.WriteLine("List : " + lst[0].aa); | |
Console.WriteLine(); | |
Console.WriteLine(); | |
Console.WriteLine(); | |
Console.WriteLine("Class"); | |
List<b> lst2 = new List<b>(); | |
b st2 = new b(); | |
st2.aa = "a"; | |
lst2.Add(st2); | |
Console.WriteLine("Struct"); | |
Console.WriteLine("Data : " + st2.aa); | |
Console.WriteLine("List : " + lst2[0].aa); | |
Console.WriteLine(); | |
st2.aa = "b"; | |
Console.WriteLine("Data : " + st2.aa); | |
Console.WriteLine("List : " + lst2[0].aa); | |
Console.WriteLine(); | |
Console.WriteLine(); | |
Console.WriteLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment