使用命名空间内的引用与根级别

时间:2015-12-24 01:44:47

标签: c# .net

这样做有什么好处:

namespace a
{
    using System;

    class ClassA
    {

    }
}

这个

using System;

namespace a
{
     class ClassA
     {
     }
}

是否有任何性能优势或最佳实践?

1 个答案:

答案 0 :(得分:3)

由于命名空间解析在编译时完成,因此在运行时肯定没有性能差异,我怀疑编译时间差异是否显着。

我见过的所有C#代码都在文件顶部有Process: GoogleAppEngineLauncher [964] Path: /Applications/GoogleAppEngineLauncher.app/Contents/MacOS/GoogleAppEngineLauncher Identifier: com.google.GoogleAppEngineLauncher Version: 1.9.30 (1.9.30.439) Code Type: X86 (Native) Parent Process: ??? [1] Responsible: GoogleAppEngineLauncher [964] User ID: 501 Date/Time: 2015-12-24 09:37:34.140 +0900 OS Version: Mac OS X 10.11.2 (15C50) Report Version: 11 Anonymous UUID: A37D6515-A732-FEB4-F4F5-6683B95CD3F3 Time Awake Since Boot: 730 seconds System Integrity Protection: enabled Crashed Thread: 0 Dispatch queue: com.apple.main-thread Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000020 Exception Note: EXC_CORPSE_NOTIFY VM Regions Near 0x20: --> __TEXT 0000000000001000-000000000001c000 [ 108K] r-x/rwx SM=COW /Applications/GoogleAppEngineLauncher.app/Contents/MacOS/GoogleAppEngineLauncher Application Specific Information: objc_msgSend() selector name: hash Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 libobjc.A.dylib 0x9c78bcaf objc_msgSend + 31 1 com.apple.Foundation 0x905bcb82 probeGC + 68 2 com.apple.Foundation 0x905bcb18 -[NSConcreteMapTable objectForKey:] + 45 3 com.apple.UIFoundation 0x92d435bd +[__NSFontTypefaceInfo typefaceInfoForPostscriptName:options:] + 128 4 com.apple.UIFoundation 0x92d4a6a5 __NSGetMetaFontInstance + 1067 5 com.google.GoogleAppEngineLauncher 0x0000c34e 0x1000 + 45902 6 com.google.GoogleAppEngineLauncher 0x0000c4a2 0x1000 + 46242 7 com.google.GoogleAppEngineLauncher 0x0000c5ae 0x1000 + 46510 8 com.google.GoogleAppEngineLauncher 0x00011319 0x1000 + 66329 9 com.apple.Foundation 0x907332f2 __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_2 + 50 10 com.apple.CoreFoundation 0x9c22dd14 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20 11 com.apple.CoreFoundation 0x9c22dc5b ___CFXRegistrationPost_block_invoke + 75 12 com.apple.CoreFoundation 0x9c22d22c _CFXRegistrationPost + 460 13 com.apple.CoreFoundation 0x9c22cf66 ___CFXNotificationPost_block_invoke + 54 14 com.apple.CoreFoundation 0x9c2269f3 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1715 15 com.apple.CoreFoundation 0x9c102e22 _CFXNotificationPost + 626 16 com.apple.Foundation 0x905ae1c5 -[NSNotificationCenter postNotificationName:object:userInfo:] + 92 17 com.apple.Foundation 0x906f7942 _performFileHandleSource + 1558 18 com.apple.CoreFoundation 0x9c17933f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15 19 com.apple.CoreFoundation 0x9c16aa1b __CFRunLoopDoSources0 + 523 20 com.apple.CoreFoundation 0x9c169e42 __CFRunLoopRun + 994 21 com.apple.CoreFoundation 0x9c1697f6 CFRunLoopRunSpecific + 390 22 com.apple.CoreFoundation 0x9c16965b CFRunLoopRunInMode + 123 23 com.apple.HIToolbox 0x933932f1 RunCurrentEventLoopInMode + 267 24 com.apple.HIToolbox 0x933930f3 ReceiveNextEventCommon + 503 25 com.apple.HIToolbox 0x93392eec _BlockUntilNextEventMatchingListInModeWithFilter + 99 26 com.apple.AppKit 0x9923f512 _DPSNextEvent + 1053 27 com.apple.AppKit 0x9964a0b0 -[NSApplication _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1057 28 com.apple.AppKit 0x9923ef8b -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 121 29 com.apple.AppKit 0x9923412f -[NSApplication run] + 1063 30 com.apple.AppKit 0x991af025 NSApplicationMain + 1630 31 com.google.GoogleAppEngineLauncher 0x00002600 0x1000 + 5632 32 com.google.GoogleAppEngineLauncher 0x0000259d 0x1000 + 5533 33 com.google.GoogleAppEngineLauncher 0x000024c8 0x1000 + 5320 个语句,所以我认为更多"正常"。