I would like to understand why you might want to use the global::
prefix. In the following code, ReSharper is identifying it as redundant, and able to be removed:
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
It is best to use the global namespace prefix in generated code. This is done to avoid situations where a similar named type exists in your namespace.
If you create a type named
System.Diagnostics.DebuggerNonUserCodeAttribute
inside your namespace you will notice that ReSharper no longer says that theglobal::
is not needed. The code generator simply wants to avoid any collisions with the names of your own types.Source: https://msdn.microsoft.com/en-us/library/cc713620.aspx
The keyword
global::
causes the compiler to bind names starting in the global namespace as opposed to in the current context. It's needed in places where a bindable member exists in a given context that has the same name as a global one and the global one is desired.For example
The corresponding MSDN page has a few more examples (including the one above)