'System.Windows.Forms.FolderBrowserDialog'是一种类型而不是命名空间

Gal*_*led 1 c# namespaces using

有可能我错过了一些非常明显但现在我看不到的东西.我有参考System.Windows.Forms,我有下一个using课程:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;

using System.Windows.Forms;
using System.Windows.Forms.FolderBrowserDialog;
Run Code Online (Sandbox Code Playgroud)

但编译器总是给我下一个错误:

错误CS0138:using namespace指令只能应用于名称空间; 'System.Windows.Forms.FolderBrowserDialog'是一种类型而不是命名空间

Cal*_*ers 8

你做不到

using System.Windows.Forms.FolderBrowserDialog;
Run Code Online (Sandbox Code Playgroud)

因为它一个类型而不是命名空间.它所属的命名空间是System.Windows.Forms.删除此行,如果要实例化a FolderBrowserDialog并确保您拥有该行

using System.Windows.Forms;
Run Code Online (Sandbox Code Playgroud)

做一个FolderBrowserDialog像这样:

var fbd = new FolderBrowserDialog();
Run Code Online (Sandbox Code Playgroud)

所有这些都与Java形成对比,在Java中,您导入的类型使用命名空间,这可能是您可能出错的地方 - 在Java中您可以执行以下操作:

import System.Windows.Forms.FolderBrowserDialog;
Run Code Online (Sandbox Code Playgroud)

然后就可以使用它了.