Namespace in C#: File-Scoped, using and global using (.NET 10)

Namespace in C#: a StoreApp project tree where the Billing and Shipping folders map to the Lakeview.Store.Billing and Lakeview.Store.Shipping namespaces

Two classes called Order, one for billing and one for shipping, and the compiler needs to know which one you mean. That’s the whole reason namespaces exist. Quick answer: A namespace in C# is a named scope that groups related types and keeps their names unique. Declare it with namespace Lakeview.Store.Billing; and import it elsewhere … Read more >>

How to Convert String to Int with Leading Zeros in C#

Convert string to int with leading zeros in C#: int.Parse turns "00042" into 42 and ToString("D5") formats it back as 00042

Parsing “00042” in C# gives you 42, every time. When you convert a string to int, leading zeros are dropped, because an int stores a value, not the digits you typed. In this tutorial, I’ll pin down how to convert string to int with leading zeros in C# on .NET 10: parse the number, then … Read more >>

Enum in C#: Declare, Convert, Flags and JSON (.NET 10)

Enum in C#: a table of Enum.TryParse with ignoreCase and Enum.IsDefined results for Shipped, shipped, Lost, 42 and 2

Status code 3 means nothing to whoever reads your code next year. Shipped means everything, and the compiler can check it for you. Quick answer: An enum in C# is a value type that gives names to a fixed set of integer constants. Declare it with enum OrderStatus { Pending, Paid, Shipped }, cast it … Read more >>

Events in C#: Build an Order Service Step by Step (.NET 10)

Events in C#: an OrderPlaced event raised by OrderService runs the audit and email subscribers attached with +=

Our Seattle warehouse team wanted an audit line for every order and an email when a standing desk drops below five units. Events in C# handle that cleanly: the order code announces what happened and never needs to know who’s listening. In this tutorial, I’ll build that order service step by step and show you … Read more >>