Skip to main content

C# Reference

v1.0.0

Searchable reference for C# types, collections, LINQ, async/await, string methods, and exceptions.

43 entries found

intData Types

int x = 42;

32-bit signed integer.

int count = 0;
longData Types

long x = 9999999999L;

64-bit signed integer.

doubleData Types

double d = 3.14;

64-bit floating-point.

decimalData Types

decimal d = 1.99m;

128-bit high-precision decimal — use for money.

boolData Types

bool flag = true;

Boolean true/false.

stringData Types

string s = "hello";

Immutable sequence of characters.

charData Types

char c = 'A';

Single Unicode character.

varData Types

var x = 42;

Implicitly typed local variable — type inferred at compile time.

Nullable<T>Data Types

int? x = null;

Value type that can also hold null.

string? name = null;
objectData Types

object obj = 42;

Base type of all .NET types.

List<T>Collections

var list = new List<int>();

Dynamic array — O(1) index, O(n) insert.

list.Add(1); list.Remove(1);
Dictionary<K,V>Collections

var d = new Dictionary<string, int>();

Hash-map — O(1) lookup by key.

d["key"] = 42;
HashSet<T>Collections

var set = new HashSet<string>();

Unordered collection of unique values.

set.Add("a"); set.Contains("a");
Queue<T>Collections

var q = new Queue<int>();

FIFO queue.

q.Enqueue(1); q.Dequeue();
Stack<T>Collections

var st = new Stack<int>();

LIFO stack.

st.Push(1); st.Pop();
IEnumerable<T>Collections

IEnumerable<int> nums = list;

Base interface for all sequences — supports foreach.

ArrayCollections

int[] arr = new int[5];

Fixed-size sequential collection.

var arr = new[] { 1, 2, 3 };
WhereLINQ

list.Where(x => x > 0)

Filters a sequence by a predicate.

nums.Where(n => n % 2 == 0)
SelectLINQ

list.Select(x => x * 2)

Projects each element into a new form (map).

list.Select(s => s.ToUpper())
OrderByLINQ

list.OrderBy(x => x.Name)

Sorts ascending by key.

people.OrderBy(p => p.Age)
GroupByLINQ

list.GroupBy(x => x.Category)

Groups elements by a key.

items.GroupBy(i => i.Type)
FirstOrDefaultLINQ

list.FirstOrDefault(x => x > 5)

Returns first matching element or default(T).

Any / AllLINQ

list.Any(x => x > 0)

Returns bool — any/all elements satisfy predicate.

CountLINQ

list.Count(x => x > 0)

Returns count of matching elements.

ToList / ToArrayLINQ

query.ToList()

Materialises a lazy query into a concrete collection.

async / awaitAsync/Await

public async Task<T> FooAsync()

Defines an asynchronous method that can be awaited.

var result = await GetDataAsync();
TaskAsync/Await

Task<int> t = DoWorkAsync();

Represents an in-progress async operation.

Task.WhenAllAsync/Await

await Task.WhenAll(t1, t2)

Awaits multiple tasks concurrently.

ConfigureAwaitAsync/Await

.ConfigureAwait(false)

Avoids capturing the synchronisation context — use in library code.

CancellationTokenAsync/Await

CancellationToken ct

Propagates cancellation signal to async operations.

await task.WaitAsync(ct);
ContainsString Methods

str.Contains("sub")

Returns true if the string contains the substring.

StartsWith / EndsWithString Methods

str.StartsWith("He")

Tests the beginning or end of a string.

SubstringString Methods

str.Substring(start, length)

Extracts a portion of the string.

ReplaceString Methods

str.Replace("old", "new")

Returns a new string with occurrences replaced.

SplitString Methods

str.Split(',')

Splits string into an array by a separator.

Trim / TrimStart / TrimEndString Methods

str.Trim()

Removes leading/trailing whitespace.

String.Format / $""String Methods

$"Hello {name}"

String interpolation — embeds expressions in string literals.

string.IsNullOrEmptyString Methods

string.IsNullOrEmpty(str)

Returns true if string is null or has zero length.

try / catch / finallyExceptions

try { } catch (Exception e) { } finally { }

Structured exception handling block.

throwExceptions

throw new ArgumentNullException(nameof(param));

Throws an exception.

ArgumentNullExceptionExceptions

new ArgumentNullException(nameof(x))

Thrown when a null argument is passed to a method that doesn't accept it.

InvalidOperationExceptionExceptions

throw new InvalidOperationException(msg)

Method call invalid for the current state of the object.

when filterExceptions

catch (Exception e) when (e.Message.Contains("x"))

Filters exceptions without unwinding the stack.