# UNIVERSAL CHEAT SHEET (Console & GUI) =========================================================================== */ using System; using System.Collections.Generic; // Required for Lists using System.Drawing; // Required for GUI Colors using System.Windows.Forms; // Required for GUI Controls // 1. BASIC PROGRAM STRUCTURE namespace MyApp { class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); } } } // 2. VARIABLES & DATA TYPES int age = 25; // Whole numbers double pi = 3.14; // Standard decimals decimal price = 19.99m; // Money (requires 'm') string name = "Gemini"; // Text bool isReady = true; // True/False var autoType = 50; // Compiler infers 'int' const float Gravity = 9.8f; // Constant (cannot change) // 3. INPUT / OUTPUT & STRINGS Console.Write("Enter text: "); string input = Console.ReadLine(); // Get user input Console.WriteLine($"Hi {input}!"); // String Interpolation ($) string upper = input.ToUpper(); // Convert to uppercase int length = input.Length; // Get character count // 4. MATH & COMPARISON int sum = 10 + 2; // 12 int rem = 10 % 3; // 1 (Remainder) bool check = (10 > 5); // true bool and = (true && false); // false (AND) bool or = (true || false); // true (OR) // 5. CONTROL FLOW (LOGIC) if (age >= 18) { Console.WriteLine("Adult"); } else { Console.WriteLine("Minor"); } switch (age) { case 21: Console.WriteLine("Legal"); break; default: Console.WriteLine("Other"); break; } // 6. LOOPS for (int i = 0; i < 5; i++) { // Run 5 times Console.WriteLine(i); } foreach (var item in myList) { // Loop through collections Console.WriteLine(item); } while (isReady) { // Run while condition is true isReady = false; } // 7. COLLECTIONS int[] nums = {1, 2, 3}; // Fixed-size Array List list = new List(); // Dynamic List list.Add("Item"); list.Remove("Item"); // 8. METHODS (FUNCTIONS) // Access | ReturnType | Name(Parameters) public static int Square(int n) { return n * n; } // 9. CLASSES & OOP class Animal { public string Species { get; set; } // Property public void MakeSound() { // Method Console.WriteLine("Noise!"); } } Animal myDog = new Animal(); myDog.Species = "Canine"; // 10. ERROR HANDLING try { int zero = 0; int crash = 5 / zero; } catch (Exception ex) { Console.WriteLine(ex.Message); } // =========================================================================== // GUI BASICS (Windows Forms) // =========================================================================== /* COMMON CONTROLS: - Label (lbl): Displays text - TextBox (txt): User input field - Button (btn): Clickable action - ComboBox (cmb): Dropdown menu */ // GET/SET TEXT string userText = txtInput.Text; // Read from TextBox lblStatus.Text = "Processing..."; // Write to Label // BUTTON CLICK EVENT private void btnSubmit_Click(object sender, EventArgs e) { MessageBox.Show("Hello!"); // Pop-up Alert } // UI STYLING & LOGIC btnSubmit.Enabled = false; // Gray out button lblError.Visible = true; // Show hidden label this.BackColor = Color.LightBlue; // Change window color // MESSAGE BOX WITH LOGIC DialogResult result = MessageBox.Show("Exit?", "Confirm", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { Application.Exit(); } // DROPDOWNS (ComboBox) cmbOptions.Items.Add("Option A"); // Add item string selected = cmbOptions.SelectedItem.ToString(); // Get selection