为什么我可以在不引用任何程序集的情况下使用System.Collections.Generic命名空间? [英] Why am I able to use System.Collections.Generic namespace without having a reference to any assembly?

查看:151
本文介绍了为什么我可以在不引用任何程序集的情况下使用System.Collections.Generic命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 References 节点中删除了所有引用,但是我仍然可以使用System.Collections.Generic命名空间.为什么?是因为Visual Studio默认以某种方式添加了它们吗?但是,如果是这样的话,我至少应该能够在我的 .csproj 文件中看到它.

I removed all references from the References node but I am still able to use System.Collections.Generic namespace. Why? Is it because Visual Studio somehow adds them by default? But if that is the case, I should be able to see it my .csproj file at least.

这是怎么回事?

推荐答案

List<T> 的文档说,该类在mscorlib中定义.这对于其中的每个C#项目都是自动隐式可用的.必须使用它,因为它是定义基本类型(例如objectvoidstringint)的同一程序集.如果没有这些代码,您将无法编写C#代码,这就是为什么要对该程序集进行特殊处理的原因.

The documentation for List<T> says the class is defined in mscorlib. This is automatically implicitly available to every C# project out there. It has to be, because it's the same assembly which defines basic types such as object, void, string, int. You're not going to be able to write C# code without those, that's why the assembly is given special treatment.

有很多方法可以抑制其包含,但这仅在您打算重新实现整个.NET运行时时才有用,否则将无法使用生成的程序集.

There are ways to suppress its inclusion, but that's only useful if you intend to re-implement the whole .NET runtime, you won't be able to use the resulting assembly otherwise.

这篇关于为什么我可以在不引用任何程序集的情况下使用System.Collections.Generic命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆