Why can't I write IO.Directory.GetFiles?

 ̄綄美尐妖づ 提交于 2019-12-08 19:08:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!