Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么intellisense使用指令工作,但在使用名称空间指定类型时不工作?_C#_.net_Visual Studio 2010 - Fatal编程技术网

C# 为什么intellisense使用指令工作,但在使用名称空间指定类型时不工作?

C# 为什么intellisense使用指令工作,但在使用名称空间指定类型时不工作?,c#,.net,visual-studio-2010,C#,.net,Visual Studio 2010,我可以使用System.Configuration添加语句使用intellisense访问我的代码,但当我访问类型ConfigurationManager时,我无法获得任何intellisense 为什么intellisense在输入using指令时起作用,但在从该命名空间指定类型时不起作用 using System.Configuration; namespace TestDBMSConnection { class Program { static void

我可以使用System.Configuration添加语句
使用intellisense访问我的代码,但当我访问类型
ConfigurationManager
时,我无法获得任何intellisense

为什么intellisense在输入using指令时起作用,但在从该命名空间指定类型时不起作用

using System.Configuration;

namespace TestDBMSConnection
{
    class Program
    {
        static void Main(string[] args)
        {
            var dataProviderName = ConfigurationManager.AppSettings["provider"];
        }
    }
}

我可以通过添加对System.Configuration的引用来解决此问题,但我不明白为什么不需要这样做,intellisense才能为using指令工作。

命名空间中的类不必位于同一程序集中

System.Configuration命名空间中的某些类位于System.dll(例如)中,而其他一些类位于System.Configuration.dll(例如)中

IntelliSense只能建议引用程序集中的类和命名空间。因此,如果引用的是System.dll,而不是System.Configuration.dll,则IntelliSense可以建议System.Configuration命名空间和System.dll中的System.Configuration类,但不建议System.Configuration.dll中的那些类


IntelliSense也无法知道某个类可能位于哪个未引用的程序集中。因此,在使用System.Configuration.dll之前,必须手动引用它。

命名空间中的类不必位于同一程序集中

System.Configuration命名空间中的某些类位于System.dll(例如)中,而其他一些类位于System.Configuration.dll(例如)中

IntelliSense只能建议引用程序集中的类和命名空间。因此,如果引用的是System.dll,而不是System.Configuration.dll,则IntelliSense可以建议System.Configuration命名空间和System.dll中的System.Configuration类,但不建议System.Configuration.dll中的那些类


IntelliSense也无法知道某个类可能位于哪个未引用的程序集中。因此,在使用System.Configuration.dll之前,您必须手动引用它。

因为intellisense for
using
会显示已知名称空间的列表。和
System.Configuration
命名空间已被引用(此命名空间中的某些类位于System.dll或mscorlib.dll中),而
ConfigurationManager
类位于未被引用的System.Configuration.dll中,因此intellisense不知道它。

因为intellisense for
使用
会显示已知名称空间的列表。和
System.Configuration
命名空间已被引用(此命名空间中的某些类位于System.dll或mscorlib.dll中),而
ConfigurationManager
类位于未被引用的System.Configuration.dll中,因此,intellisense对此一无所知。

为了测试这一点,我创建了一个控制台应用程序,并删除了所有引用。我可以编译并运行它。使用intellisense,我可以使用System.Configuration创建指令。我没想到能做到这一点,因为并没有对系统的引用。是否存在对引用System.Configuration的程序集的某些自动引用?@Martin Jasper:mscorlib.dll程序集始终被隐式引用,并包含System.Configuration.Assembles命名空间中的某些类。mscorlib.dll包含命名空间System.Configuration.Assembles中的某些对象。Mscorlib将自动引用,除非您取消选中该选项以将其包含在项目设置中。intellisense本身也可能正在查看基本.NET程序集,如mscorlib、System等。我可以看到System.Core和mscorlib自动添加到我的项目中,方法是单击“添加引用”,并看到它们已被选中,即使我在解决方案资源管理器中没有看到它们的列表。使用ildasm,我可以看到System.core没有对System.Configuration的引用,但mscorlib通过System.Configuration.Assembly进行引用,正如@Tergiver所提到的。谢谢你的帮助,我知道现在发生了什么。为了测试这一点,我创建了一个控制台应用程序并删除了所有引用。我可以编译并运行它。使用intellisense,我可以使用System.Configuration创建指令。我没想到能做到这一点,因为并没有对系统的引用。是否存在对引用System.Configuration的程序集的某些自动引用?@Martin Jasper:mscorlib.dll程序集始终被隐式引用,并包含System.Configuration.Assembles命名空间中的某些类。mscorlib.dll包含命名空间System.Configuration.Assembles中的某些对象。Mscorlib将自动引用,除非您取消选中该选项以将其包含在项目设置中。intellisense本身也可能正在查看基本.NET程序集,如mscorlib、System等。我可以看到System.Core和mscorlib自动添加到我的项目中,方法是单击“添加引用”,并看到它们已被选中,即使我在解决方案资源管理器中没有看到它们的列表。使用ildasm,我可以看到System.core没有对System.Configuration的引用,但mscorlib通过System.Configuration.Assembly进行引用,正如@Tergiver所提到的。谢谢你的帮助,我知道现在发生了什么。谢谢亚历克斯。您是否有任何特定的文档/博客/代码用于深入了解intellisense的工作原理?谢谢Alex。您是否有任何特定的文档/博客/代码用于深入了解intellisense的工作原理?