Skip to content

Armitage1982/NamingConventions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 

Repository files navigation

C# Naming Conventions

Based on Microsoft documentation Capitalization Conventions & Hr Rony Article on C# Corner


Object Name Notation Example
Namespace PascalCase namespace System.Security { ... }
Class PascalCase public class StreamReader { ... }
Constructor PascalCase public class Person { public Person(string lastName, string firstName) { ... }}
Interface PascalCase public interface IEnumerable { ... }
Method PascalCase public class Object { public virtual string ToString(); }
Constants PascalCase public const int Months = 12;
struct PascalCase public struct Coords { ... }
Property PascalCase public string Name { get => name; }
Event PascalCase public class Process { public event EventHandler Exited; }
Delegate PascalCase public delegate void ProcessBookDelegate(Book book);
Enum value PascalCase public enum FileMode { Alpha, Beta, Gamma }
Public Field PascalCase public string Day;
Private Field camelCase private DateTime date;
Parameter camelCase public static class Convert { public static int ToInt32(string value); }
Local variable camelCase public class Object { public Do() { int index = 0; } }

Basically use PascalCase everywhere except for parameters, local variable and Private Field.

Private Field is subject to many interpretations but I find this solution elegant and it works well with the Visual Studio encapsulation helper so I adopted it


Why not using _underscore ?

Alt text


How about Constructor then ?

Alt text


What about Var ?

I am also not inclined to use var outside LINQ and anonymous types

Alt text

'var' should not be used in simple declarations, as shown below:

Alt text

About

C# Naming Conventions based on Microsoft documentation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published