???????????????????????????????????????????

????д??????????????????

public class StackNum<T> where T : struct
{
List<T> array = null;
public StackNum()
{
this.array = new List<T>();
}
public void Push(T value)
{
array.Add(value);
}
public T Pop()
{
T val = array[this.Length - 1];
this.array.Remove(val);
return val;
}
public int Length
{
get { return this.array.Count; }
}
}

????StackNum

??????????????д????????????

class StackTestHelper
{
public static void LengthTest<T>()
where T : struct
{
var stack = GetStackInstance<T>();
Assert.AreEqual(stack.Length?? 0);
}
public static void PushTest<T>()
where T : struct
{
var stack = GetStackInstance<T>();
stack.Push(default(T));
Assert.AreEqual(stack.Length?? 1);
}
public static void PopTest<T>(params T[] values)
where T : struct
{
var stack = GetStackInstance<T>();
if (values == null)
{
return;
}
int pushLength = 0;
foreach (T val in values)
{
stack.Push(val);
Assert.AreEqual(stack.Length?? ++pushLength);
}
for (int i = stack.Length - 1; i >= 0; i--)
{
Assert.AreEqual<T>(stack.Pop()?? values[i]);
Assert.AreEqual(stack.Length?? i);
}
}
public static StackNum<T> GetStackInstance<T>()
where T : struct
{
return new StackNum<T>();
}
}