Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.3k views
in Technique[技术] by (71.8m points)

c# - 'System.Windows.Forms.FolderBrowserDialog' is a type not a namespace

It is possible that I'm missing something very obvious but now I can not see now. I have the reference to System.Windows.Forms and I have the next using classes:

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;

But the compiler always give to me the next error:

error CS0138: A using namespace directive can only be applied to namespaces; 'System.Windows.Forms.FolderBrowserDialog' is a type not a namespace

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You cannot do

using System.Windows.Forms.FolderBrowserDialog;

as it is a type and not a namespace. The namespace it belongs to is System.Windows.Forms. Remove this line and if you want to instantiate a FolderBrowserDialog and just make sure you have the line

using System.Windows.Forms;

and make a FolderBrowserDialog like so:

var fbd = new FolderBrowserDialog();

All this is in contrast to Java, where you import types not use namespaces, which is where you may be going wrong - in Java you would do something like:

import System.Windows.Forms.FolderBrowserDialog;

and then be able to use it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...