类型或命名空间名称';堆栈';找不到(仅适用于.NET 4.0)

本文关键字:适用于 NET 堆栈 命名空间 类型 找不到 | 更新日期: 2023-09-27 18:25:59

编译此程序时出错:

using System;
using System.Collections.Generic;
static class main {
    public static void Main() {
        Stack<int> a;
    }
};

使用此cmd:

C:'Users'tomc'Desktop'l>C:'Windows'Microsoft.NET'Framework64'v4.0.30319'csc test.cs

我得到这个错误:

test.cs(12,3):error CS0246:类型或命名空间名称"Stack"不能为已找到(您是否缺少using指令或程序集引用?)

但是,当使用此命令时,它构建得很好:C:'Users'tomc'Desktop'l>C:'Windows'Microsoft.NET'Framework64'v3.5'csc test.cs

堆栈是否已从.NET 4中删除?我找不到任何迹象表明它在MSDN上

类型或命名空间名称';堆栈';找不到(仅适用于.NET 4.0)

C#编译器有一个默认的"配置"文件(称为响应文件),位于.NET Framework安装目录(c:'Windows'Microsoft.NET'Framework64'v4.0.30319'csc.rsp)中。此响应文件只是一个文本文件,其中包含一组编译器命令行开关,这些开关在编译程序时默认传递。除了默认文件之外,您还可以指定自己的文件(请参阅上面的链接)

在您的情况下,此文件可能丢失或损坏。您可以检查是否存在对核心库的引用。例如,下面是我的机器上的csc.rsp文件:

# This file contains command-line options that the C#
# command line compiler (CSC) will process as part
# of every compilation, unless the "/noconfig" option
# is specified. 
# Reference the common Framework libraries
/r:Accessibility.dll
/r:Microsoft.CSharp.dll
/r:System.Configuration.dll
/r:System.Configuration.Install.dll
/r:System.Core.dll
/r:System.Data.dll
/r:System.Data.DataSetExtensions.dll
/r:System.Data.Linq.dll
/r:System.Data.OracleClient.dll
/r:System.Deployment.dll
/r:System.Design.dll
/r:System.DirectoryServices.dll
/r:System.dll
/r:System.Drawing.Design.dll
/r:System.Drawing.dll
/r:System.EnterpriseServices.dll
/r:System.Management.dll
/r:System.Messaging.dll
/r:System.Runtime.Remoting.dll
/r:System.Runtime.Serialization.dll
/r:System.Runtime.Serialization.Formatters.Soap.dll
/r:System.Security.dll
/r:System.ServiceModel.dll
/r:System.ServiceModel.Web.dll
/r:System.ServiceProcess.dll
/r:System.Transactions.dll
/r:System.Web.dll
/r:System.Web.Extensions.Design.dll
/r:System.Web.Extensions.dll
/r:System.Web.Mobile.dll
/r:System.Web.RegularExpressions.dll
/r:System.Web.Services.dll
/r:System.Windows.Forms.Dll
/r:System.Workflow.Activities.dll
/r:System.Workflow.ComponentModel.dll
/r:System.Workflow.Runtime.dll
/r:System.Xml.dll
/r:System.Xml.Linq.dll