Using the directive to import namespaces

If I import the namespace as follows:

using System;

Why can't I access the IO submenu as follows:

IO.FileInfo fi;

Introduced I have to write either the whole path:

System.IO.FileInfo fi;

Or import the full I / O namespace and use a class without a namespace

using System.IO;

FileInfo fi;

Did I miss something?

+3
source share
3 answers

Although it is often convenient to think in terms of namespaces and subspaces, in reality only type names exist.

In this case, there is one type: System.IO.FileInfo

using System. , , . IO.FileInfo, IO, FileInfo .

, , , . .

+5

# . .

System System.IO - , #.

FileInfo, :

using FileInfo = System.IO.FileInfo;
+2

, , , , :

namespace System {
  class MyClass {
    IO.FileInfo fi;
  }
}

, :

namespace System {
  using IO;
}
0

Source: https://habr.com/ru/post/1793671/


All Articles