Is there any kind of naming convention for C# WinForms code? I Googled this a bit and got nowhere fast.
I'm designing a WinForms app and the Class View is becoming tough to navigate fast, so I need to apply some standards to find things faster.
New (typical) control When you drag a new control onto a form in VS, it assigns it a camel cased name, but generates a private member field. I thought the convention for private class members was camel case prefixed with an underscore?
What about events & methods for controls placed on a form? Is the Studio default of ControlName_MethodName the way to go for eveything?
No, the convention in .NET is typically to not use underscores at all. There are exceptions like in the event handlers but for most things usually there are no underscores. Other than event handlers, I do not use underscores. I use camel casing for private members and functions and pascal casing for public members (properties) and functions. However, other people have different standards. Some people like to use the C++ convention of doing _someVariable or m_someVariable. I don't do this though.
I rarely use hungarian, but I do use hungarian for GUI controls (So a submit button might be btnSubmit, or a list box of customers would be lstCustomers).
As far as event handlers, you know, this is a bit of a gray area for me. If I use the Visual Studio "tab-complete" way of creating event handlers, I will typically leave the name as is. This, of course, introduces the underscores. However, if I don't, and it is not a GUI component, sometimes I just use the camelCasing. Probably for event handlers, it would be a good practice use the VS default naming scheme. I think it's fine as long as you stay relatively consistent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With