C# Essentials Cheat Sheet
A quick reference guide to fundamental C# syntax, data structures, and programming concepts for efficient development.
Core Principles
- Understand console input/output for basic interaction.
- Master data type conversions for flexible data handling.
- Utilize string manipulation for text processing.
- Grasp arithmetic operators for calculations.
- Employ switch expressions for concise conditional logic.
- Implement loops (while, do-while, for) for repetitive tasks.
- Understand logical operators for complex conditions.
- Work with arrays and Lists for ordered collections.
- Leverage Dictionaries for key-value pair storage.
- Implement Random number generation for variability.
- Structure code with classes, methods, and constructors.
- Understand access modifiers (public, private, protected).
- Implement properties for controlled data access.
- Handle exceptions gracefully with try-catch blocks.
- Utilize inheritance and polymorphism for code reuse.
- Implement interfaces and abstract classes for design patterns.
- Understand generics for type-safe, reusable code.
- Master deep copying for independent object duplication.
- Implement comparison logic with IComparable and IEquatable.
- Use string interpolation for formatted output.
Key Terms
- Console.WriteLine(): Outputs text to the console, followed by a new line.
- Console.Write(): Outputs text to the console without a new line.
- Console.ReadLine(): Reads a line of text input from the console.
- Convert.ToInt32(): Converts a value to a 32-bit signed integer.
- Convert.ToChar(): Converts a value to a character.
- Convert.ToDouble(): Converts a value to a double-precision floating-point number.
- x.Length: Gets the number of characters in a string.
- x.ToUpper(): Converts a string to uppercase.
- x.ToLower(): Converts a string to lowercase.
- x.Trim(): Removes leading and trailing whitespace from a string.
- x.Split(): Splits a string into substrings based on delimiters.
- % (Modulo): Returns the remainder of a division.
- switch expression: A concise way to evaluate an expression against multiple patterns.
- while loop: Executes a block of code as long as a condition is true.
- do-while loop: Executes a block of code once, then repeats as long as a condition is true.
- for loop: Executes a block of code a specified number of times.
- List<T>: A generic collection representing a dynamically sized array.
- Dictionary<TKey, TValue>: A collection of key-value pairs.
- Random.Next(): Generates a random integer within a specified range.
- Random.NextDouble(): Generates a random double between 0.0 and 1.0.
- static: Members belong to the class itself, not to instances.
- const: A member whose value is fixed at compile time.
- readonly: A member that can only be assigned a value once.
- inheritance: Allows a class to inherit properties and methods from another class.
- override: Allows a derived class to provide a specific implementation of a method inherited from a base class.
- interface: A contract that defines a set of members a class must implement.
- abstract class: A class that cannot be instantiated and may contain abstract methods.
- generic: Allows types to be specified as parameters, enabling type safety and code reuse.
- deep copy: Creates a completely new copy of an object and its contained objects.
- IComparable: Interface for defining natural ordering of objects.
- IEquatable: Interface for defining value equality between objects.