泛型报错,很简单的几行代码,但是找不出原因,求指导。
程序代码:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace test
{
class MyStack<T>
{
public T[] Myarray;
public int count;
public MyStack(int m)
{
Myarray = new T[m];
count = 0;
}
public void push(T a)
{
Myarray[count++] = a;
}
public T pull()
{
return Myarray[--count];
}
}
class Program
{
static void Main(string[] args)
{
MyStack<int> myStack = new MyStack<int>(10);
myStack.push(1);
myStack.push(2);
myStack.push(3);
for (int i = 0; 1 < 3; i++)
{
Console.WriteLine(myStack.pull());
}
}
}
}
上面是代码和截图。







