.NET Core Fundamental Libraries

The .NET Core platform provides a rich set of fundamental libraries that form the backbone of application development. These libraries offer essential types and services for building robust and performant applications.

Key Namespace Overviews

System Namespace

The System namespace is the foundational namespace in .NET Core. It contains fundamental types that represent fundamental values and operations, including:

Example: Basic type conversion:

int number = 123;
string text = Convert.ToString(number);
Console.WriteLine(text); // Output: 123

System.Collections Namespace

This namespace provides interfaces and classes that define collections of objects. These include:

Example: Using a List<T>:

var names = new List<string>();
names.Add("Alice");
names.Add("Bob");
foreach (var name in names)
{
    Console.WriteLine(name);
}

System.IO Namespace

The System.IO namespace provides types that allow reading and writing to files and data streams, as well as types that represent and manipulate various kinds of files and directories.

Example: Reading from a file:

try
{
    using (StreamReader reader = new StreamReader("example.txt"))
    {
        string line;
        while ((line = reader.ReadLine()) != null)
        {
            Console.WriteLine(line);
        }
    }
}
catch (FileNotFoundException)
{
    Console.WriteLine("The file was not found.");
}

System.Net Namespace

This namespace provides a simple programming model for many of the data transmission protocols in the Internet protocol suite.

Example: Making an HTTP GET request:

using (HttpClient client = new HttpClient())
{
    HttpResponseMessage response = await client.GetAsync("https://www.example.com");
    response.EnsureSuccessStatusCode(); // Throw if HTTP status is not 2xx
    string responseBody = await response.Content.ReadAsStringAsync();
    Console.WriteLine(responseBody.Substring(0, 100) + "..."); // Print first 100 chars
}

System.Text Namespace

The System.Text namespace contains types that represent character encodings and classes that perform conversions between character encodings.

Example: Using StringBuilder for efficient string concatenation:

var builder = new StringBuilder();
for (int i = 0; i < 5; i++)
{
    builder.Append("Item ").Append(i).Append(" ");
}
string result = builder.ToString();
Console.WriteLine(result); // Output: Item 0 Item 1 Item 2 Item 3 Item 4

System.Threading Namespace

This namespace provides types that support multi-threaded programming, including types that define and manage threads, synchronization primitives, and concurrent collections.

Example: Starting a new thread:

void PrintMessage(object message)
{
    Console.WriteLine(message);
}

Thread newThread = new Thread(PrintMessage);
newThread.Start("Hello from a new thread!");

Discover More

This is just a glimpse into the extensive .NET Core library ecosystem. For detailed information on specific classes, methods, and properties, please refer to the dedicated documentation pages for each namespace.

Frequently Used Types

Namespace Class/Type Description
System String Represents text as a sequence of characters. Immutable.
System.Collections.Generic List<T> Represents a list of objects that can be accessed by index. Dynamically sized.
System.IO File Provides static methods for the creation, copying, deletion, moving, and opening of files.
System.Net.Http HttpClient Sends HTTP requests and receives HTTP responses from a resource identified by a URI.
System.Text StringBuilder Represents a mutable sequence of characters. Efficient for multiple string manipulations.
System.Threading.Tasks Task Represents an asynchronous operation.