# Skill 02 - C# Language Fundamentals ## Core Concepts C# code is made of keywords, identifiers, literals, operators, expressions, statements, blocks, members, types, namespaces, and assemblies. ## Naming Rules - Use `PascalCase` for public types, methods, properties, events, and constants. - Use `camelCase` for local variables and parameters. - Use `_camelCase` for private fields when that is the project convention. - Name things by meaning, not by type suffix, except accepted suffixes like `Async`, `Options`, `Exception`, `Attribute`, and `Controller`. ## Variables and Constants - Use `var` when the right side makes the type obvious. - Use explicit types when they improve clarity or prevent accidental narrowing. - Use `const` only for compile-time constants that will not change. - Use `readonly` fields for values set during construction. - Prefer immutable data where practical. ## Strings - Use string interpolation for readable formatting. - Use `StringBuilder` for repeated string mutation in loops. - Be explicit about culture for user-facing versus machine-readable formatting. - Use ordinal comparisons for identifiers, keys, codes, and protocol values. - Use culture-aware comparisons only for human language sorting/searching. ## Console and Script-Like Code - Top-level statements are fine for small apps, samples, and tools. - Move logic into functions or classes once behavior needs tests. - Keep `Program.cs` thin in production apps. ## Style Rules - Prefer clarity over language cleverness. - Avoid unnecessary `dynamic`; use it only for genuinely dynamic data boundaries. - Prefer pattern matching when it makes type and shape checks clearer. - Use `nameof(...)` instead of string literals for member names.