为什么我不能编写IO.Directory.GetFiles? [英] Why can't I write IO.Directory.GetFiles?

查看:129
本文介绍了为什么我不能编写IO.Directory.GetFiles?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来自VB.Net环境,在该环境中先使用Imports System,然后使用IO.Directory.GetFiles(...).

I come from a VB.Net environment, where using Imports System and then IO.Directory.GetFiles(...) works.

另一方面,似乎using System;不足以在没有System.前缀的情况下编写使用IO.Directory的功能.唯一的解决方法似乎是 using IO = System.IO;

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;

为什么?

示例代码:

using System;
using System.IO;

namespace Test {
    class Program {
        static void Main(string[] args) {
            System.Console.WriteLine(IO.Directory.GetFiles(System.Environment.CurrentDirectory)[0]);
        }
    }
}

我的问题不是如何使代码正常工作,而是为什么我不能编写IO.Directory.GetFiles?"

My question is not what should I do to get my code working, but specifically "why cant I write IO.Directory.GetFiles ??"

推荐答案

添加

使用System.IO;

using System.IO;

,您将拥有预期的行为.如果没有using指令(或完全限定条件),C#不会使子名称空间可用.

and you'll have the behavior you expect. C# does not make child namespaces available without a using directive (or full qualification.)

这篇关于为什么我不能编写IO.Directory.GetFiles?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆