First program, namespaces and keywords (C# Language)
๐ Full lesson with practice questions on DevLadder (free, lesson 2 of 38 in the C# Language: Basics to Advanced course) Classic program structure (what every C# file looked like before C# 9, and what top-level statements generate for you): using System ; // import a namespace so you can write Console instead of System.Console namespace Divakar . Shop // logical grouping of types; usually matchesโฆ
The source material discusses the basics of C# programming, focusing on program structure, namespaces, keywords, and naming conventions. A classic C# file, before C# 9, had a top-level "using" statement and a "namespace" section containing an internal class named "Program" with a "Main" method as the entry point.
The modern equivalent in C# 10+ uses top-level statements, with a "global" using statement that applies to all files in the project, and file-scoped namespaces in separate files. Namespaces help prevent name clashes and are used to group types logically, often matching the directory structure.
Keywords in C# are reserved words with special meanings, such as "class", "int", "if", "return", "public", "static", "new", "this", "base", "null", "true". Contextual keywords like "var", "async", "await", "get", "set", "init", "value", "yield", "record", "required", "where", "select", "field" can be used in specific contexts, but they cannot be used as identifiers otherwise.
Naming conventions in C# involve PascalCase for types, methods, properties, and namespaces, while locals and parameters use camelCase. Private fields typically use "_camelCase", while interfaces start with "I". Async methods end with "Async".
The source also covers the differences between value and reference types, with value types holding their data directly and reference types referencing objects on the heap. String is immutable, while StringBuilder is mutable and more efficient for frequent concatenations. Const, readonly, and static readonly are constants with varying scopes and lifetimes, with const being compile-time, readonly instance field-specific, and static readonly type-specific.
The source highlights that changes to const values in one library do not affect other libraries until the library is recompiled.
Written by urgent.news from Dev.to's reporting โ not their text. Machine-written โ may contain errors; check the original before relying on it.