Coding Style in C#

Because we don't have a style for Dr. A that isn't C# ;-O

These are taken from: https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions When in doubt, see that page.

Variable Names

ALWAYS!!! Use meaningful names! Its fine to use x as a int for a loop, but otherwise your variable names should be descriptive enough for any programmer to infer its purpose.

Public, Protected and Internal Variables | Class, Record and Struct

All of these are meant to be publicly visible (or in the second case, at least visible to someone) to classes in the assembly, therefore they use the same style: PascalCase. IF HOWEVER, you are using a variable name that is the same as the class name/enum name/... then use CamelCase without an _ prefix.

E.g. HelloWorld

Private

All of these are meant to be visible only inside the class they are defined and should be prefixed with an underscore and be in CamelCase.

E.g. _helloWorld

Private static

Prefix the _ with the letter s.

E.g. s_helloWorld.

Caveat: Dr. A doesn't mind if you are doing public static readonly values that are assigned at definition to be all caps with words separated by underscores.

E.g. public static readonly string HELLO_WORLD = "Hello world";

Comments

Please place a space after the // or

Implicitly typed variables

Implicitly typed variables are always private, and should be used only when it is clear to the user what the type is.

dynamic

Unless you really need it AND you know what you are doing, do not use dynamic!

Delegates

Use Func<> and Action<> instead of delegate whenever possible (i.e. always).

ClassesPage/CodingStyle (last edited 2023-02-23 18:40:48 by scot)