C# Reference
v1.0.0Searchable reference for C# types, collections, LINQ, async/await, string methods, and exceptions.
43 entries found
int x = 42;
32-bit signed integer.
int count = 0;
long x = 9999999999L;
64-bit signed integer.
double d = 3.14;
64-bit floating-point.
decimal d = 1.99m;
128-bit high-precision decimal — use for money.
bool flag = true;
Boolean true/false.
string s = "hello";
Immutable sequence of characters.
char c = 'A';
Single Unicode character.
var x = 42;
Implicitly typed local variable — type inferred at compile time.
int? x = null;
Value type that can also hold null.
string? name = null;
object obj = 42;
Base type of all .NET types.
var list = new List<int>();
Dynamic array — O(1) index, O(n) insert.
list.Add(1); list.Remove(1);
var d = new Dictionary<string, int>();
Hash-map — O(1) lookup by key.
d["key"] = 42;
var set = new HashSet<string>();
Unordered collection of unique values.
set.Add("a"); set.Contains("a");var q = new Queue<int>();
FIFO queue.
q.Enqueue(1); q.Dequeue();
var st = new Stack<int>();
LIFO stack.
st.Push(1); st.Pop();
IEnumerable<int> nums = list;
Base interface for all sequences — supports foreach.
int[] arr = new int[5];
Fixed-size sequential collection.
var arr = new[] { 1, 2, 3 };list.Where(x => x > 0)
Filters a sequence by a predicate.
nums.Where(n => n % 2 == 0)
list.Select(x => x * 2)
Projects each element into a new form (map).
list.Select(s => s.ToUpper())
list.OrderBy(x => x.Name)
Sorts ascending by key.
people.OrderBy(p => p.Age)
list.GroupBy(x => x.Category)
Groups elements by a key.
items.GroupBy(i => i.Type)
list.FirstOrDefault(x => x > 5)
Returns first matching element or default(T).
list.Any(x => x > 0)
Returns bool — any/all elements satisfy predicate.
list.Count(x => x > 0)
Returns count of matching elements.
query.ToList()
Materialises a lazy query into a concrete collection.
public async Task<T> FooAsync()
Defines an asynchronous method that can be awaited.
var result = await GetDataAsync();
Task<int> t = DoWorkAsync();
Represents an in-progress async operation.
await Task.WhenAll(t1, t2)
Awaits multiple tasks concurrently.
.ConfigureAwait(false)
Avoids capturing the synchronisation context — use in library code.
CancellationToken ct
Propagates cancellation signal to async operations.
await task.WaitAsync(ct);
str.Contains("sub")
Returns true if the string contains the substring.
str.StartsWith("He")
Tests the beginning or end of a string.
str.Substring(start, length)
Extracts a portion of the string.
str.Replace("old", "new")
Returns a new string with occurrences replaced.
str.Split(',')
Splits string into an array by a separator.
str.Trim()
Removes leading/trailing whitespace.
$"Hello {name}"
String interpolation — embeds expressions in string literals.
string.IsNullOrEmpty(str)
Returns true if string is null or has zero length.
try { } catch (Exception e) { } finally { }
Structured exception handling block.
throw new ArgumentNullException(nameof(param));
Throws an exception.
new ArgumentNullException(nameof(x))
Thrown when a null argument is passed to a method that doesn't accept it.
throw new InvalidOperationException(msg)
Method call invalid for the current state of the object.
catch (Exception e) when (e.Message.Contains("x"))
Filters exceptions without unwinding the stack.