【问题标题】:'System.Windows.Forms.FolderBrowserDialog' is a type not a namespace'System.Windows.Forms.FolderBrowserDialog' 是一种类型而不是命名空间
【发布时间】:2011-12-31 16:25:38
【问题描述】:

我可能遗漏了一些非常明显的东西,但现在我看不到了。我有对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;

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

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

【问题讨论】:

  • 错误信息很明确,我觉得不需要额外解释...
  • 是的,我想我会删除这个问题。
  • 我发现 java 脑损伤。

标签: c# namespaces using


【解决方案1】:

你做不到

using System.Windows.Forms.FolderBrowserDialog;

因为它一个类型而不是一个命名空间。它所属的命名空间是System.Windows.Forms。删除这一行,如果你想实例化 FolderBrowserDialog 并确保你有这行

using System.Windows.Forms;

并像这样创建FolderBrowserDialog

var fbd = new FolderBrowserDialog();

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

import System.Windows.Forms.FolderBrowserDialog;

然后就可以使用了。

【讨论】:

    【解决方案2】:

    using 指令导入命名空间,而不是类型。

    导入System.Windows.Forms 后,您可以使用其中的所有类型,包括FolderBrowserDialog

    【讨论】:

      【解决方案3】:

      似乎 System.Windows.Forms.FolderBrowserDialog 不是命名空间,而是属于命名空间System.Windows.Forms的类。

      *.Forms.FolderBrowserDialog 是位于该命名空间内的一个类。 Here is an example of how it should be used。 (示例在页面底部)

      【讨论】:

        【解决方案4】:

        那是因为它是一种类型,而不是命名空间。您不引用 using 语句中的类型,只引用命名空间。这不是 Java。

        【讨论】:

          【解决方案5】:

          System.Windows.Forms.FolderBrowserDialog 是一个类,不是使用它的命名空间,请清除该行。

          【讨论】:

            【解决方案6】:

            现在您正在尝试导入 FolderBrowserDialog 但它实际上是一个对象。要使用它,请删除:

            using System.Windows.Forms.FolderBrowserDialog;
            

            而引用是通过创建这样的对象...

            FolderBrowserDialog x = new FolderBrowserDialog();
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2019-04-19
              • 2018-04-13
              • 2015-07-22
              • 2021-03-31
              • 2018-03-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多