C# Cheat Sheet
Practical C# cheat sheet with setup steps, core workflows, debugging, and copy-paste examples.
csharp dotnet c syntax examples
C# cheat sheet with real commands and snippets for setup, core workflows, debugging, and production-safe automation patterns. If you are working across tools, pair this with the SQL Cheat Sheet and Docker Cheat Sheet.
Setup and Tooling
Goal: Install and verify language toolchain
# Run dotnet command
dotnet --version
# Run dotnet command
dotnet new console -n App
# Run cd command
cd App
Core Workflows
Goal: Run and build source code
# Execute dotnet workflow
dotnet run
# Execute dotnet workflow
dotnet build
Goal: Use a practical code snippet
using System;
public class Program
{
public static void Main()
{
Console.WriteLine("Hello C#");
}
}
Testing and Formatting
Goal: Run automated tests
# Execute test-related command
dotnet test
# Execute test-related command
dotnet test --collect:"XPlat Code Coverage"
Goal: Run lint and formatter checks
# Execute quality command
dotnet format
# Execute quality command
dotnet build -warnaserror
Automation and CI
Goal: Create a repeatable CI shell step
# Run strict shell mode for CI step
set -euo pipefail
# Install dependencies deterministically
npm ci || pip install -r requirements.txt || true
# Run tests and fail fast on errors
dotnet test
Debugging and Troubleshooting
Goal: Trace runtime issues
# Print runtime and package manager versions
node --version || python --version || true
# Search stack traces and TODO markers
rg "Traceback|Exception|TODO" .
# Re-run tests with verbose output
dotnet test -v || dotnet test --verbose || true
Common Gotchas
- Pin C# language/runtime versions in local and CI environments.
- Keep formatting and linting automated to avoid noisy diffs in code review.
- Prefer explicit dependency lock files for reproducible builds.
- Write small, deterministic tests that can run quickly in pre-commit checks.
- Document compiler/interpreter flags used in production builds.
Related Sheets
- SQL Cheat Sheet — query patterns, joins, and data analysis.
- Docker Cheat Sheet — container build, run, and image lifecycle workflows.
- CSS Cheat Sheet — daily CSS commands and production-ready examples.
Related Cheat Sheets
Docker Cheat Sheet
Practical Docker cheat sheet with setup steps, core workflows, debugging, and copy-paste examples.
CSS Cheat Sheet
Practical CSS cheat sheet with setup steps, core workflows, debugging, and copy-paste examples.
SQL Cheat Sheet
Practical SQL cheat sheet with setup steps, core workflows, debugging, and copy-paste examples.