namespaces

C# - Declaration of types within a namespace

▼魔方 西西 提交于 2020-01-03 16:44:14
问题 what could be a possible use of declaring types within a namespace but not in a class. For ex: namespace Test { public delegate void Ispossible(); } This is valid & does not generate any compilation errors but i can't think of why we would declare it this way as opposed to inside a class. 回答1: A namespace is a high-level unit of organization within .NET. Declaring types within classes is typically frowned upon (but, as with all things, it's not a 100% rule) because it can make the types more

Does use statement order affect functionality in PHP?

那年仲夏 提交于 2020-01-03 13:33:18
问题 I've been using PHP's namespaces for some time now and I think it is a great addition to my programming. This morning I wondered about something concerning the use statement. I'm wondering if the order of use affects the functonality of my PHP code. According to PHP.net The ability to refer to an external fully qualified name with an alias, or importing, is an important feature of namespaces. This is similar to the ability of unix-based filesystems to create symbolic links to a file or to a

Is it possible to add a C++ namespace to all symbols from a C library?

泄露秘密 提交于 2020-01-03 13:33:12
问题 I'm modifying a large C++ project, which defines in one of its main headers an enum FooBar. That enum gets included everywhere, and sadly is not namespaced. From that project I'd like to use a C library, which unfortunately also defines an enum FooBar in the same global namespace. I can't change the library implementation, and it's difficult to rename or namespace the enum in the C++ project because it's used all over the place. So ideally I would add a namespace to all symbols coming from

Is it possible to add a C++ namespace to all symbols from a C library?

 ̄綄美尐妖づ 提交于 2020-01-03 13:33:07
问题 I'm modifying a large C++ project, which defines in one of its main headers an enum FooBar. That enum gets included everywhere, and sadly is not namespaced. From that project I'd like to use a C library, which unfortunately also defines an enum FooBar in the same global namespace. I can't change the library implementation, and it's difficult to rename or namespace the enum in the C++ project because it's used all over the place. So ideally I would add a namespace to all symbols coming from

Is it legal C++ to declare a nested namespace `std`?

ⅰ亾dé卋堺 提交于 2020-01-03 12:33:28
问题 The std namespace is special in C++, so ... Is this legal C++? // at global scope namespace mine { namespace std { ... } } I'd call it insane, but is it allowed? A reference (or non-reference) from the Standard would be appreciated. 回答1: In the reserved names standard 17.4.3.1 (and its sub-paragraphs) I can't find anything that prohibits using std as a nested namespace name. It's not a macro, it's not in the global namespace, and it doesn't seem to meet any of the "external linkage criteria"

Is fully qualified naming vs the using directive simply a matter of opinion?

ぃ、小莉子 提交于 2020-01-03 12:30:52
问题 I find now that I work in a mostly solo environment that I actually type fully qualified methods calls more and more, instead of make use of the using directive. Previously, I just stayed consistent with the most prominent coding practice on the team. Personally, I find it easier to read verbose code at a glance, I type fast especially with autocompletion and I find myself using Google more often as my source of documentation, which a fully qualified name returns a much narrower results set.

Is fully qualified naming vs the using directive simply a matter of opinion?

元气小坏坏 提交于 2020-01-03 12:30:42
问题 I find now that I work in a mostly solo environment that I actually type fully qualified methods calls more and more, instead of make use of the using directive. Previously, I just stayed consistent with the most prominent coding practice on the team. Personally, I find it easier to read verbose code at a glance, I type fast especially with autocompletion and I find myself using Google more often as my source of documentation, which a fully qualified name returns a much narrower results set.

Why is circular dependency allowed with namespaces in c#?

百般思念 提交于 2020-01-03 09:25:34
问题 In c# you're allowed to have a statement in file a.cs (which has namespace of MyApp.A): using MyApp.B; while file b.cs (which has namespace of MyApp.B) already have the statement using MyApp.A; If a similar dependency would exist in different dll's (where a.dll has a reference to b.dll and vice versa) it wouldn't be allowed because of circular dependency error, so why is it allowed with namespaces (and compiler doesn't even produce a warning)? Isn't it a code smell to do so anyway? 回答1:

Conditionally compiling entire namespaces - C#

让人想犯罪 __ 提交于 2020-01-03 07:29:13
问题 I was wondering if there is a way to conditionally compile entire namespaces in C#. Or am I left with having to explicitly decorate each source file within the namespace with the preprocessor directives to exclude it? In sub-versions of my application the code in various namespace is simply not required and I would like it excluded. Thanks in advance! 回答1: If your namespace is in a separate assembly which doesn't contain anything else you can use the Configuration Manager for your specific

.net : namespace : what is exact difference in writing USING directives before or after namespace [duplicate]

﹥>﹥吖頭↗ 提交于 2020-01-03 04:18:07
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Should Usings be inside or outside the namespace .NET namespaces and using statements What is exact difference in writing USING directives before or after namespace declaration. Example : using System; using System.Linq; using NUnit.Framework; namespace HostTest { /** code goes here **/ } and namespace HostService { using System.Runtime.Serialization; using System; /** code goes here **/ } 回答1: Darin's answer is