Skip to content

Instantly share code, notes, and snippets.

@RyuaNerin
Created March 17, 2014 11:12
Show Gist options
  • Save RyuaNerin/9597518 to your computer and use it in GitHub Desktop.
Save RyuaNerin/9597518 to your computer and use it in GitHub Desktop.
Struct 와 Class 의 메모리 참조를 비교하는 파일
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