Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ??"

like image 678
Clément Avatar asked Feb 24 '12 15:02

Clément


1 Answers

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.)

like image 169
Matt T Avatar answered Sep 21 '22 19:09

Matt T