Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In what order should I place properties, events, functions, function overrides, etc. in C# classes? [duplicate]

Tags:

c#

readability

When creating a new C# class I am not certain of what the best logical order for declaring properties, event delegates, functions, function overrides, etc. are and what considerations should be taken into account when deciding on that order.

Typically when creating the code behind class of a WebUserControl I end up placing things in this order:

  1. Events
  2. Properties
  3. Life Cycle Event override functions
  4. Other functions

Is there a more logical way to do this and what considerations should I be making when deciding on how to order these elements of the class within the class file?

like image 706
Chris Magnuson Avatar asked Nov 28 '22 12:11

Chris Magnuson


1 Answers

Does not make any difference to the compilation, you might want to wrap the sections in #region to make it easier for someone reading your code to know where they are and keeping them organized. It probably should be a coding standard for your company so all code is organized similarly and is less frustrating to look at...

like image 95
CSharpAtl Avatar answered Dec 16 '22 02:12

CSharpAtl