Capitalization/Naming Convention for Controls
What is the best a开发者_运维百科nd recommended practice regarding capitalization for naming controls in, for example, WinForms?
StyleCop says that instances of classes should start with a lower case letter. I respect this convention in my code.
In previous languages that I have used, for example VB6, I have been used to name my UI controls dropped on the form starting with an upper case character, like ZipCodeTextBox.
But a control dropped on a form actually is little more than an instance of a class, so it would make sense for the StyleCop rule to apply, so, zipCodeTextBox. Most of the naming conventions document do not go further and do not specifically cover the UI controls.
I have seen code using the two naming conventions in various projects, books, and blogs posts, so I'm curious what is the generally recommended practice on this and why?
Thanks.
That's covered in the MSDN documentation here: http://msdn.microsoft.com/en-us/library/ms229002.aspx
There is, of course, room for flexibility, but in my own humble opinion, I think you're better off sticking with these guidelines, as they will be recognized by most .Net developers.
However, for controls, we veer from the standards in our shop... We allow hungarian notation on form controls. It's not standard, but it's a lot easier to know you're looking for a textbox, and start typing "txt" and have intellisense bring up the list of textboxes on your form. We realize it's not standard, and it's not as nice looking in code, but it speeds productivity enough to make it a fair trade-off.
精彩评论