Using Statements vs Namespace path? C#

前端 未结 6 415
耶瑟儿~
耶瑟儿~ 2020-11-30 11:19

I recently stopped using using-statements and instead use the full namespace path of any .net object that I call.

Example:

using System;    

namespa         


        
6条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 11:37

    There is zero performance difference because the compiler ALWAYS puts in the full name - using is only a hint for the compiler, the runtime doesn't know or support that.

    However, once you memorize where the objects come from you will look at this as silly and verbose. There is just so much noise and people just know that Path is from System.IO, Console is in System and StringBuilder is in System.Text.

    One downside of your approach: Without using, no extension methods outside of the current namespace. Have fun writing System.Linq.Enumerable.Where(inputSequence,...) instead of just inputSequence.Where(...) :)

提交回复
热议问题