我怎样才能以编程方式将字符串数组推入通用堆栈?
字符串数组
string[] array=new string[]{"Liza","Ana","Sandra","Diya"};
Run Code Online (Sandbox Code Playgroud)
堆栈设置
public class stack<T>
{
private int index;
List<T> list;
public stack()
{
list = new List<T>();
index=-1;
}
public void Push(T obj)
{
list.Add(obj);
index++;
}
...........
}
Run Code Online (Sandbox Code Playgroud)
我需要改变什么?
stack<string> slist = new stack<string>();
var v = from vals in array select (p => slist.Push(p));
Run Code Online (Sandbox Code Playgroud)
错误报告 :
The type of the expression in the select clause is incorrect.