[c#] 간단한 Generic List
public class GenericList<T>
{
private class Node
{
private Node next;
private T data;
public Node(T t)
{
next = null;
data = t;
}
public Node Next
{
get { return next; }
set { next = value; }
}
public T Data
{
get { return data; }
set { data = value; }
}
}
private Node head;
public GenericList()
{
head = null;
}
public void Add(T t)
{
Node n = new Node(t);
n.Next = head;
head = n;
}
public IEnumerator<T> GetEnumerator()
{
Node current = head;
while (current != null)
{
yield return current.Data;
current = current.Next;
}
}
}
{
private class Node
{
private Node next;
private T data;
public Node(T t)
{
next = null;
data = t;
}
public Node Next
{
get { return next; }
set { next = value; }
}
public T Data
{
get { return data; }
set { data = value; }
}
}
private Node head;
public GenericList()
{
head = null;
}
public void Add(T t)
{
Node n = new Node(t);
n.Next = head;
head = n;
}
public IEnumerator<T> GetEnumerator()
{
Node current = head;
while (current != null)
{
yield return current.Data;
current = current.Next;
}
}
}
private 클래스 Node 와 그를 이용한 IEnummerator 구현 –> 제네릭 리스트 구현
참고 : (미친바바’s) http://blog.naver.com/baba1092?Redirect=Log&logNo=130093943245
'C#' 카테고리의 다른 글
[C# Simple Callback] C# 의 정말 간단한 콜백 호출방법 (77) | 2011.01.06 |
---|---|
[c#] 익명타입의 (열거)배열 (71) | 2010.12.06 |
[c#] 간단한 Generic List (221) | 2010.12.06 |
[C# ,쉬운 이터레이터 만들기] Yield 키워드 간단히 개념잡기 (188) | 2010.12.05 |
[AS3 , C# ,Serialize]AS3 와 C#의 직렬화 비교 (90) | 2010.12.04 |
[c# TCP socket] Clinet가 죽은것을 알아채기 (68) | 2010.12.04 |
C#
2010.12.06 11:31