Hen*_*all -1 .net c# generics stack
我正在使用.NETFramework,Version = v4.5并尝试创建以下堆栈:
using System;
using System.Collections;
using System.Collections.Generic;
...
Stack<int> s = new Stack<int>();
Run Code Online (Sandbox Code Playgroud)
为什么我收到此错误?
类'System.Collections.Stack'没有类型参数
没有类型参数的堆栈工作正常.
这对我有用:
using System.Collections.Generic;
namespace HashSetPerformance
{
public class SampleStack
{
public SampleStack()
{
Stack<int> s = new Stack<int>();
}
}
}
Run Code Online (Sandbox Code Playgroud)
只需看一下:MSDN-Generic-Stack-Class
确保你没有这样做:
using System.Collections; // This has to be: using System.Collections.Generic;
namespace HashSetPerformance
{
public class SampleStack
{
public SampleStack()
{
Stack<int> s = new Stack<int>();
}
}
}
Run Code Online (Sandbox Code Playgroud)
因为它使用非泛型类型Stack-Class:MSDN-Stack-Class