Show Menu
Cheatography

Programming in C# Cheat Sheet (DRAFT) by

Key syntax and concepts of C# and have a quick reference guide to the basics of C# programming.

This is a draft cheat sheet. It is a work in progress and is not finished yet.

1. Basic Structure

 //'using' allows for easier access to types in a namespace.
using System;

//Namespaces organize code and prevent naming collisions.
namespace YourNamespace
{
    class YourClass //A 'class' defines the blueprint of objects.
    {
        static void Main(string[] args) //'Main' is where the program starts execution.
        {
            Console.WriteLine("Hello, World!"); //Displays text in the console.
        }
    }
}

2. Data Types

int
whole numbers
double­/float
decimals
char
single character
string
text
bool
true/false

Condit­ional Statements

if (age > 18) {
    Console.WriteLine("Adult");
} else {
    Console.WriteLine("Minor");
}

switch (grade) {
    case "A":
        Console.WriteLine("Excellent");
        break;
    default:
        Console.WriteLine("Unknown grade");
        break;
}