相关疑难解决方法(0)

使用LINQ将项目推入堆栈

我怎样才能以编程方式将字符串数组推入通用堆栈?

字符串数组

 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.

c# linq

4
推荐指数
1
解决办法
4045
查看次数

标签 统计

c# ×1

linq ×1