S
S
splunk2016-03-09 02:45:57
.NET
splunk, 2016-03-09 02:45:57

WITH#. Why is it necessary to write using System.ChildNamespace when using System is already indicated?

In theory, the System space should include nested ones, for example, System.Collections and others.
Why list them separately?
Is it necessary to write System.Collections and, for example, System.Collections.Generic separately?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Roman, 2016-03-09
@splunk

It shouldn't, these are logically different visibility zones. Plus, classes with the same names can be located in different namespaces, here your compiler will go crazy, and for each mention of a class you will need to make a clarification in the form of a full name.

H
heartdevil, 2016-03-09
@heartdevil

Hello.
Namespaces are just a logical division of code. Physically, code in System is not required to include code in System.Collections or any other code prefixed with System.(prefix). System -- simply indicates that you are including some system kernel code.
Here you can see the naming

A
Alexey Pavlov, 2016-03-09
@lexxpavlov

Often, you can not write using at all, and classes are always specified in full:

System.Int32 i = 10;
System.Console.WriteLine("Строка");
System.Collections.Generic.List<int> list = new System.Collections.Generic.List<int>();

But if you specify using-and, then you can write less (and therefore almost always better):
Int32 i = 10;
Console.WriteLine("Строка");
List<int> list = new List<int>();

If two different classes with the same name are used in one file, then in this case you can write one of the classes through using, and the second one - write the full name. Or you can create a class alias:
using IntList = System.Collections.Generic.List<int>;

IntList lst = new IntList();
List<double> lst2 = new List<double>();

In general, using- and are used for convenience - less writing.
PS If you use Resharper, it will show that there are extra namespaces here: imgur.com/kYvWJqe In this case, the gray words can be safely removed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question