Quantcast
Channel: Order of items in classes: Fields, Properties, Constructors, Methods - Stack Overflow
Browsing all 17 articles
Browse latest View live

Answer by user14165724 for Order of items in classes: Fields, Properties,...

I have restructured the accepted answer, as to what I think is a better layout:Within a class, struct or interface:Constant FieldsReadonly FieldsFieldsEventsPropertiesIndexersConstructorsFinalizers...

View Article



Answer by user6630825 for Order of items in classes: Fields, Properties,...

I know this is old but my order is as follows:in order of public, protected, private, internal, abstractConstantsStatic VariablesFieldsEventsConstructor(s)MethodsPropertiesDelegatesI also like to write...

View Article

Answer by Aluan Haddad for Order of items in classes: Fields, Properties,...

My preference is to order by kind and then be decreasing visibility as followspublic methodspublic eventspublic propertiesprotected methodsprotected eventsprotected propertiesprivate methodsprivate...

View Article

Answer by bright for Order of items in classes: Fields, Properties,...

This is an old but still very relevant question, so I'll add this: What's the first thing you look for when you open up a class file that you may or may not have read before? Fields? Properties? I've...

View Article

Answer by Jonathan Wright for Order of items in classes: Fields, Properties,...

According to the StyleCop Rules Documentation the ordering is as follows.Within a class, struct or interface: (SA1201 and SA1203)Constant FieldsFieldsConstructorsFinalizers...

View Article


Answer by Pat for Order of items in classes: Fields, Properties,...

I keep it as simple as possible (for me at least)EnumerationsDeclarationsConstructorsOverridesMethodsPropertiesEvent Handler

View Article

Answer by Michael Damatov for Order of items in classes: Fields, Properties,...

Usually I try to follow the next pattern:static members (have usually an other context, must be thread-safe, etc.)instance membersEach part (static and instance) consists of the following member...

View Article

Answer by Wedge for Order of items in classes: Fields, Properties,...

I prefer to put the private fields up at the top along with the constructor(s), then put the public interface bits after that, then the private interface bits.Also, if your class definition is long...

View Article


Answer by Mitchel Sellers for Order of items in classes: Fields, Properties,...

As mentioned before there is nothing in the C# language that dictates the layout, I personally use regions, and I do something like this for an average class.public class myClass{#region Private...

View Article


Answer by blowdart for Order of items in classes: Fields, Properties,...

From StyleCopprivate fields, public fields, constructors, properties, public methods, private methodsAs StyleCop is part of the MS build process you could view that as a de facto standard

View Article

Answer by Ryan Lundy for Order of items in classes: Fields, Properties,...

Rather than grouping by visibility or by type of item (field, property, method, etc.), how about grouping by functionality?

View Article

Answer by Elijah Manor for Order of items in classes: Fields, Properties,...

I would recommend using the coding standards from IDesign (webarchive) or the ones listed on Brad Abram's website. Those are the best two that I have found.Brad would say...Classes member should be...

View Article

Answer by Wayne for Order of items in classes: Fields, Properties,...

I don't know about a language or industry standard, but I tend to put things in this order with each section wrapped in a #region:using StatementsNamespaceClassPrivate membersPublic...

View Article


Answer by Rory Becker for Order of items in classes: Fields, Properties,...

The closest you're likely to find is "Design Guidelines, Managed code and the .NET Framework" (http://blogs.msdn.com/brada/articles/361363.aspx) by Brad Abrams Many standards are outlined here. The...

View Article

Answer by Hamish Smith for Order of items in classes: Fields, Properties,...

the only coding guidelines I've seen suggested for this is to put fields at the top of the class definition.i tend to put constructors next.my general comment would be that you should stick to one...

View Article


Answer by Jeff Kotula for Order of items in classes: Fields, Properties,...

There certainly is nothing in the language that enforces it in any way. I tend to group things by visibility (public, then protected, then private) and use #regions to group related things...

View Article

Order of items in classes: Fields, Properties, Constructors, Methods

Is there an official C# guideline for the order of items in terms of class structure?Does it go:Public FieldsPrivate FieldsPropertiesConstructorsMethods?I'm curious if there is a hard and fast rule...

View Article

Browsing all 17 articles
Browse latest View live


Latest Images