C# .NET API Documentation

Explore the vast landscape of APIs available for C# development on the .NET platform. This documentation provides comprehensive details, examples, and best practices for utilizing .NET libraries.

Core .NET Libraries

The foundational libraries that power all .NET applications.

System namespace: Contains fundamental classes for representing data types, handling exceptions, and performing basic operations.

// Example: Working with strings string message = "Hello, .NET!"; Console.WriteLine(message.ToUpper());

System.Collections namespace: Provides interfaces and classes for common collection types like lists, dictionaries, and queues.

// Example: Using a List List<string> names = new List<string> { "Alice", "Bob", "Charlie" }; names.Add("David"); foreach (var name in names) { Console.WriteLine(name); }

System.IO namespace: Enables reading from and writing to various data sources, including files, streams, and console.

// Example: Reading from a file using (StreamReader reader = new StreamReader("myFile.txt")) { string line; while ((line = reader.ReadLine()) != null) { Console.WriteLine(line); } }

Web Development (ASP.NET Core)

Build modern, cloud-ready, internet-connected applications with ASP.NET Core.

Microsoft.AspNetCore.Mvc: Classes for building Model-View-Controller (MVC) web applications.

ControllerBase.Ok(Object result): Returns an OK response (200) with a JSON serialized body.

Microsoft.AspNetCore.Http: Classes for handling HTTP requests and responses.

// Example: Accessing request headers var userAgent = HttpContext.Request.Headers["User-Agent"]; Console.WriteLine($"User Agent: {userAgent}");

Data Access (Entity Framework Core)

A modern object-relational mapper (ORM) for .NET.

Microsoft.EntityFrameworkCore: Core classes for defining entities and DbContext.

// Example: Querying data using (var context = new MyDbContext()) { var products = await context.Products.Where(p => p.Price > 100).ToListAsync(); foreach (var product in products) { Console.WriteLine($"{product.Name}: {product.Price}"); } }

Windows Desktop Development

Create rich desktop experiences on Windows.

System.Windows.Controls (WPF): UI elements for WPF applications.

// Example: Creating a Button in WPF (XAML) // <Button Content="Click Me" Click="Button_Click" />

System.Windows.Forms (WinForms): Classes for building Windows Forms applications.

// Example: Handling a button click in WinForms // private void button1_Click(object sender, EventArgs e) { // MessageBox.Show("Button clicked!"); // }

Cloud & Azure Integration

Leverage .NET to build and deploy applications on cloud platforms, especially Azure.

Microsoft.Azure.Storage.Blob: APIs for interacting with Azure Blob Storage.

// Example: Uploading a blob // var blobClient = storageAccount.CreateCloudBlobClient(); // var container = blobClient.GetContainerReference("mycontainer"); // var blockBlob = container.GetBlockBlobReference("myblob.txt"); // await blockBlob.UploadTextAsync("This is the blob content.");

Machine Learning with ML.NET

A cross-platform, open-source machine learning framework for .NET developers.

Microsoft.ML: Core classes for building ML models.

// Example: Training a sentiment analysis model // var mlContext = new MLContext(); // var dataView = mlContext.Data.LoadFromTextFile<SentimentData>(dataPath, hasHeader: true); // var pipeline = mlContext.Transforms.Text.FeaturizeText("Features", "Text") // .Append(mlContext.Transforms.Concatenate("Features", "Features")) // .Append(mlContext.BinaryClassification.Trainers.SdcaLogisticRegression(labelColumnName: "Label", featureColumnName: "Features")); // var model = pipeline.Fit(dataView);

Networking APIs

Classes for network communication.

System.Net.Http: For making HTTP requests.

System.Net.Sockets: For low-level network socket programming.

Security

APIs for cryptography, authentication, and authorization.

System.Security.Cryptography: Hashing, encryption, digital signatures.

System.Security.Claims: Working with identity and claims.

Performance & Diagnostics

Tools and APIs for profiling and optimizing applications.

System.Diagnostics: Tracing, performance counters, process management.

Serialization

Converting objects to and from various formats like JSON, XML.

System.Text.Json: High-performance JSON serializer/deserializer.

System.Xml.Serialization: XML serialization.