问题
I come from a VB.Net
environment, where using Imports System
and then IO.Directory.GetFiles(...)
works.
On the other hand, it seems that using System;
is not sufficient to write use IO.Directory
without prefixing it with System.
. The only workaround seems to be
using IO = System.IO;
Why?
Example code:
using System;
using System.IO;
namespace Test {
class Program {
static void Main(string[] args) {
System.Console.WriteLine(IO.Directory.GetFiles(System.Environment.CurrentDirectory)[0]);
}
}
}
Edit: My question is not what should I do to get my code working, but specifically "why cant I write IO.Directory.GetFiles
??"
回答1:
Add
using System.IO;
and you'll have the behavior you expect. C# does not make child namespaces available without a using directive (or full qualification.)
回答2:
The thing you are talking about is not posssible in C# that might be diffrence between C# and vb.NET.
If you are converting vb.Net code to C# than make use of this site will help you lot
vb.net to c#
Code fo ryou
System.IO.Directory.GetFiles(...)
or add
using System.IO;
will do for you
来源:https://stackoverflow.com/questions/9433012/why-cant-i-write-io-directory-getfiles