public class MyList<T>
{
private MyListNode<T> first, last;
private int _length;
public int Length {get {return _length;}}
public void Add(T item) {
var node = new MyListNode<T> {Value = item};
++_length;
if(first == null) {
first = node;
last = node;
return;
}
last.Next = node;
last = node;
}
public T Get(int pos) {
if(pos >= _length) return null;
var current = first;
for(int i = 0; i < pos; ++i) {
current = current.Next;
}
return current.Value;
}
private class MyListNode<T> {
public T Value {get; set;}
public MyListNode<T> Next {get; set;}
}
}