C# Naming Conventions: The Complete Guide with Examples

C# naming conventions cheat sheet: class, interface, method, field, event

A pull request for a Texas retailer’s order system hit my queue last week with custName, CUST_ID, and m_total in one class. That’s three naming conventions fighting inside 40 lines of C#. Here’s the quick answer. C# uses PascalCase for types, namespaces, methods, properties, events, and constants, camelCase for local variables and parameters, _camelCase for … Read more >>

C# Enum Naming Conventions: Rules and Examples (.NET 10)

C# enum naming conventions: ALL_CAPS ORDER_SHIPPED member renamed to PascalCase Shipped in a singular OrderStatus enum

This is the enum I flag most often in code reviews, and it breaks three C# enum naming conventions at once: an Enum suffix, ALL_CAPS members and the type name repeated inside every value. The fix is enum OrderStatus { Pending, Shipped, Delivered }: a singular PascalCase type with plain PascalCase members. Below are the … Read more >>

C# Field Naming Conventions: _camelCase, s_ and PascalCase (.NET 10)

C# field naming convention: name = name; flagged by CS1717 becomes _name = name; with an _camelCase private field

Most field bugs we catch in code review start with name = name; inside a constructor. It compiles with a warning, and the field stays empty, because the parameter hides the field. Quick answer: the C# field naming conventions are _camelCase for private and internal fields, s_ and t_ prefixes for static and thread-static fields, … Read more >>

C# Method Naming Conventions: PascalCase, Async and Try (.NET 10)

C# method naming conventions cheat sheet: CalculateTotal verb phrase, GetQuoteAsync suffix, TryFindPrice Try pattern and OnStockRanLow event method

Quick answer: C# method naming conventions say every method gets a PascalCase verb or verb phrase, like CalculateTotal, async methods end in Async, and parameters stay camelCase: I ran every rule below on .NET 10 against a gear store’s order code, then made the build flag the names you’d get wrong. What You Need Before … Read more >>

How to Create a GUID in C# (.NET 10 Examples + Video)

Create a GUID in C#: Guid.NewGuid() returns a version 4 GUID and Guid.CreateVersion7() a time-ordered version 7 GUID, 36 characters long

To create a GUID in C#, call Guid.NewGuid(). It gives you a random 128-bit value in the familiar 8-4-4-4-12 hex layout, so your code can make an order ID or database key without asking a server for the next number. On .NET 9 and later you also get Guid.CreateVersion7(), which puts a timestamp up front … Read more >>

C# Create Folder If Not Exists (Directory.CreateDirectory Guide)

C# create folder if not exists: Directory.CreateDirectory called twice on Reports202610-OctoberTexas with no exception

Want C# to create a folder only if it doesn’t exist? Call Directory.CreateDirectory(path). It creates the folder when it’s missing and quietly returns the existing one when it’s already there, so no check is needed. In this tutorial, I’ll cover every C# create folder if not exists case I run into: the current directory, folders … Read more >>