C# (.NET) Standard Library: Complete Overview

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

C# (.NET) Standard Library: Complete Overview



The C# (.NET) Standard Library is a fundamental set of namespaces, classes, interfaces, and methods that forms the foundation of the .NET platform. It provides the developer with ready-made solutions for most everyday tasks: from working with files and collections to multithreading and reflection. In this article, we will provide a complete overview of the key components of the C# (.NET) Standard Library with practical code examples.



1. System Namespace — The Foundation of Everything



The System namespace contains fundamental data types and base classes. This includes:



  • Base types: Object, ValueType, String, Int32, Boolean, etc.
  • Mathematical functions: the Math class (methods Abs, Pow, Sqrt).
  • Working with the console: the Console class (input/output).
  • Random number generation: the Random class.


using System;

class Program{ static void Main() { // Example of working with base types and the Math class int number = -42; int absoluteValue = Math.Abs(number); Console.WriteLine($"The absolute value of {number} is {absoluteValue}");

// Random number generation Random rnd = new Random(); int randomNumber = rnd.Next(1, 100); Console.WriteLine($"Random number from 1 to 100: {randomNumber}"); }}


2. System.Collections — Working with Collections



The System.Collections namespace and its generic version System.Collections.Generic provide classes for storing and managing groups of objects. The most popular ones are:



  • List<T> — a dynamic array.
  • Dictionary<TKey, TValue> — a key-value collection.
  • Queue<T> — a queue (first in, first out).
  • Stack<T> — a stack (last in, first out).
  • HashSet<T> — a hash set of unique elements.


using System;using System.Collections.Generic;

class Program{ static void Main() { // List List<string> fruits = new List<string> { "Apple", "Banana", "Orange" }; fruits.Add("Grape"); Console.WriteLine("List of fruits:"); foreach (var fruit in fruits) Console.WriteLine(fruit);

// Dictionary Dictionary<int, string> employees = new Dictionary<int, string>(); employees.Add(1, "Ivan"); employees.Add(2, "Maria"); Console.WriteLine($"Employee with ID 1: {employees[1]}"); }}


3. System.Linq — Language Integrated Query (LINQ)



System.Linq is one of the most powerful extensions of the C# (.NET) Standard Library. It allows you to perform complex queries on collections, databases, and XML using syntax similar to SQL. Main extension methods:



  • Where — filtering.
  • Select — projection (transformation).
  • OrderBy / OrderByDescending — sorting.
  • GroupBy — grouping.
  • Aggregate — aggregation (sum, maximum, etc.).


using System;using System.Collections.Generic;using System.Linq;

class Program{ static void Main() { List<int> numbers = new List<int> { 5, 12, 8, 21, 3, 17 };

// Filtering and sorting using LINQ var result = numbers.Where(n => n > 10)

Recommendations