C# itself has no library. It relies on a small set of types, listed in annex C of the specification, and in practice on the .NET class libraries. This page is a brief map of the namespaces. The .NET API browser documents every type.
Types the language depends on
Several language features are compiled into calls on library types. A compiler needs them to exist, and a new language version sometimes needs a newer library or runtime.
| Feature | Library types |
|---|---|
| Built-in types | System.Object, String, Int32 and the other simple types |
foreach | IEnumerable, IEnumerable<T>, IEnumerator<T> |
using | IDisposable, IAsyncDisposable |
lock | System.Threading.Monitor, System.Threading.Lock |
async, await | Task, Task<T>, ValueTask and the types in System.Runtime.CompilerServices |
| Async streams | IAsyncEnumerable<T>, IAsyncEnumerator<T> |
| Nullable value types | System.Nullable<T> |
| Tuples | System.ValueTuple |
| Ranges and indices | System.Index, System.Range |
| Spans | System.Span<T>, System.ReadOnlySpan<T> |
| Unions (C# 15) | System.Runtime.CompilerServices.UnionAttribute, IUnion, in .NET 11 |
Main namespaces
| Namespace | Contents |
|---|---|
System | Base types, Console, Math, DateTime, DateOnly, TimeOnly, Guid, Random, Span<T>, delegates such as Func and Action |
System.Collections | Older non-generic collections such as ArrayList and Hashtable |
System.Collections.Generic | List<T>, Dictionary<K, V>, HashSet<T>, Queue<T>, Stack<T>, SortedDictionary<K, V>, LinkedList<T>, PriorityQueue<T, P> |
System.Collections.Concurrent | Thread-safe collections such as ConcurrentDictionary<K, V> |
System.Collections.Immutable | Immutable collections such as ImmutableArray<T> and ImmutableList<T> |
System.Linq | Enumerable and Queryable, which implement the query operators |
System.Text | StringBuilder and Encoding |
System.Text.RegularExpressions | Regex, with source-generated forms |
System.Text.Json | JSON reading, writing and serialisation |
System.Xml, System.Xml.Linq | XML reading and writing, and the XDocument API |
System.IO | File, Directory, Path, Stream, StreamReader |
System.IO.Compression | ZipArchive, GZipStream, DeflateStream |
System.Net.Http | HttpClient |
System.Net.Sockets | Socket, TcpClient, UdpClient |
System.Threading | Thread, Interlocked, SemaphoreSlim, CancellationToken, Lock |
System.Threading.Tasks | Task, Parallel |
System.Threading.Channels | Producer and consumer channels |
System.Numerics | BigInteger, Complex, Vector<T>, and the generic maths interfaces such as INumber<T> |
System.Globalization | CultureInfo, calendars and number formatting |
System.Reflection | Metadata inspection and invocation at run time |
System.Runtime.CompilerServices | Types used by the compiler, and helpers such as Unsafe |
System.Runtime.InteropServices | Native interoperation: DllImport, Marshal, MemoryMarshal |
System.Diagnostics | Debug, Process, Stopwatch |
System.Diagnostics.CodeAnalysis | The nullable analysis attributes |
System.Security.Cryptography | Hashes, encryption and random numbers |
Frameworks add their own namespaces: Microsoft.AspNetCore for web apps,
Microsoft.Extensions for configuration, logging and dependency injection,
and System.Windows.Forms and System.Windows for desktop
applications.
NuGet packages
Libraries outside the .NET runtime are distributed through
NuGet as .nupkg
packages, and are listed with PackageReference in a
.csproj project file.