Vivek Kaushik
AboutBlogWorkMy Work Ethics
C# Methods Cheat Sheet

C# Methods Cheat Sheet

Created
Feb 23, 2026 01:31 AM
Tags

1️⃣ String Methods

Basic Operations

  • s.Length
  • s[i]
  • s.Substring(start, length)
  • s.IndexOf(charOrString)
  • s.LastIndexOf(char)
  • s.Contains(string)
  • s.StartsWith(string)
  • s.EndsWith(string)
  • s.ToLower() / s.ToUpper()
  • s.Trim()

Conversion

  • s.ToCharArray()
  • int.Parse(s)
  • Convert.ToInt32(s)
  • int.TryParse(s, out int result)

Split & Join

  • s.Split(' ')
  • string.Join(",", arr)

StringBuilder (for heavy modifications)

  • Append()
  • Insert(index, value)
  • Remove(start, length)
  • ToString()

2️⃣ Array Methods

Properties

  • arr.Length

Static Array Methods

  • Array.Sort(arr)
  • Array.Reverse(arr)
  • Array.Fill(arr, value)
  • Array.Copy(source, dest, length)
  • Array.IndexOf(arr, value)

3️⃣ List Methods

Creation

  • new List<int>()

Add/Remove

  • Add(item)
  • AddRange(collection)
  • Remove(item)
  • RemoveAt(index)
  • RemoveAll(predicate)

Access

  • list[i]
  • list.Count

Utility

  • Sort()
  • Reverse()
  • Contains(value)
  • IndexOf(value)

4️⃣ Dictionary<TKey, TValue>

Creation

  • new Dictionary<int, int>()

Core Operations

  • dict[key] = value
  • dict.ContainsKey(key)
  • dict.Remove(key)
  • dict.TryGetValue(key, out value)
  • dict.Count

5️⃣ HashSet

  • Add(value)
  • Remove(value)
  • Contains(value)
  • Count

6️⃣ Stack

  • Push(value)
  • Pop()
  • Peek()
  • Count

7️⃣ Queue

  • Enqueue(value)
  • Dequeue()
  • Peek()
  • Count

8️⃣ Math

  • Math.Max(a, b)
  • Math.Min(a, b)
  • Math.Abs(x)
  • Math.Sqrt(x)
  • Math.Pow(x, y)
  • Math.Ceiling(x)
  • Math.Floor(x)

9️⃣ LINQ (System.Linq)

Filtering

  • Where(x => condition)

Projection

  • Select(x => something)

Aggregation

  • Sum()
  • Min()
  • Max()
  • Average()
  • Count()

Element Retrieval

  • First()
  • FirstOrDefault()
  • Single()
  • SingleOrDefault()
  • Last()
  • ElementAt(index)

Ordering

  • OrderBy(x => x)
  • OrderByDescending(x => x)
  • ThenBy()

Quantifiers

  • Any()
  • All(predicate)

Conversion

  • ToList()
  • ToArray()
  • ToDictionary()

🔟 Useful Patterns

Frequency Count

  • Dictionary<char, int>
  • int[26] for lowercase letters

Two Pointer

  • left = 0, right = n-1

Sliding Window

  • HashSet<char> or Dictionary<char,int>

Prefix Sum

  • int[] prefix

Sorting with Custom Comparator

  • list.Sort((a, b) => a.CompareTo(b))

⚠️ Interview Advice

  • Avoid heavy LINQ in interviews unless asked. Write explicit loops.
  • Always mention time and space complexity.
  • Prefer in-place operations when possible.
  • Use TryGetValue instead of ContainsKey + index lookup for better performance.

Review this once before interview and you’ll recall most C# syntax instantly.
Table of Contents
1️⃣ String MethodsBasic OperationsConversionSplit & JoinStringBuilder (for heavy modifications)2️⃣ Array MethodsPropertiesStatic Array Methods3️⃣ List MethodsCreationAdd/RemoveAccessUtility4️⃣ Dictionary<TKey, TValue>CreationCore Operations5️⃣ HashSet6️⃣ Stack7️⃣ Queue8️⃣ Math9️⃣ LINQ (System.Linq)FilteringProjectionAggregationElement RetrievalOrderingQuantifiersConversion🔟 Useful PatternsFrequency CountTwo PointerSliding WindowPrefix SumSorting with Custom Comparator⚠️ Interview Advice
Copyright 2026 Vivek Kaushik