Link to namespaces globally?

Is there a way to refer to the namespace globally throughout the solution?

So, instead of these lines in each code file:

using System;
using MyNamespace;

to declare them only once, and each code file will use them.

Btw I am using Visual Studio.

+3
source share
5 answers

No, C # does not have this concept. In this regard, each source file is independent. (And if using directives are in the namespace declaration, they are independent of others, using directives in peer name names declarations too. This is a pretty rare case, although in my experience.)

ReSharper, , . Visual Studio.

EDIT: , , , ( ):

using Foo;

namespace X
{
    using Bar;
    // Foo and Bar are searched for code in here, but not Baz
}

namespace Y
{
    using Baz;
    // Foo and Baz are searched for code in here, but not Bar
}

use.

+6

, .

ReSharper, , .

+4

SO . Visual Studio.

zip: [Program Files] [Visual Studio]\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.zip

Class.cs. , Visual Studio : [ ] [Visual Studio]\Common7\IDE\ItemTemplatesCache\CSharp\Code\1033\Class.zip

+2

, Visual Studio Templates - .

, using , . , MyNamespace , . . # FAQ.

0

, , CSharp, - "refences" ( VS), " ". mulitple, .

-2

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


All Articles