问题
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. These are obviously very arbitrary reasons to prefer fully qualifying over using the using directive.
In this day and age of refactoring tools, is there a concrete reason why using the using directive is superior to fully qualified or vice versa, or is this purely a personal discretion issue like comment spacing? Finally, which do you prefer and why?
回答1:
Probably could call this subjective.
Where I work/What I prefer is to use using statements. It keeps the names/lines short enough, which just makes day to day life easier. Plus, you can just hover over something for the fully qualified name.
回答2:
I use usings whenever possible. The less there is to read, the less I have to parse:
System.Windows.Form form = new System.Windows.Form();
is just way more work than
var form = new Form();
Please note that this does require that your entire shop commits to not doing something silly, such as creating your own super-duper Form class which causes ambiguity.
回答3:
I generally prefer using/imports for real code and fully qualified code for examples/etc.
回答4:
Readability.
Think about yourself in 1 year, trying to read your code. You want it to be explicit and short and have only one point of information for each data (DRY principle).
来源:https://stackoverflow.com/questions/971612/is-fully-qualified-naming-vs-the-using-directive-simply-a-matter-of-opinion