.NET Framework

Table of Contents

Introduction

The .NET Framework is a software development platform developed by Microsoft for building and running applications on Windows. It provides a comprehensive and consistent programming model for building applications that have visually stunning user experiences, seamless and secure communication, and the ability to model a range of business processes.

Key Features:

Architecture


// .NET Framework Architecture
┌─────────────────────────────────────┐
│           User Applications         │
├─────────────────────────────────────┤
│     Framework Class Libraries       │
├─────────────────────────────────────┤
│    Common Language Runtime (CLR)    │
├─────────────────────────────────────┤
│        Operating System            │
└─────────────────────────────────────┘
    

Common Language Runtime (CLR)

CLR Features:


// Example of CLR features in action
public class ResourceManagement
{
    private IDisposable _resource;

    public void UseResource()
    {
        // CLR manages memory and resource cleanup
        using (var resource = new SomeResource())
        {
            resource.DoWork();
        } // CLR ensures Dispose is called
    }

    // CLR handles exception propagation
    public async Task ProcessDataAsync()
    {
        try
        {
            await LoadDataAsync();
        }
        catch (Exception ex)
        {
            // Exception handling with stack trace preservation
            throw new ApplicationException("Processing failed", ex);
        }
    }
}
    

Base Class Library (BCL)


// Common BCL types and usage
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;

public class BCLExample
{
    // Collections
    List<string> items = new List<string>();
    Dictionary<string, int> map = new Dictionary<string, int>();

    // File operations
    public void FileOperations()
    {
        File.WriteAllText("data.txt", "content");
        string content = File.ReadAllText("data.txt");
    }

    // LINQ operations
    public void LinqOperations()
    {
        var numbers = Enumerable.Range(1, 100);
        var evenNumbers = numbers.Where(n => n % 2 == 0);
        var sum = evenNumbers.Sum();
    }
}
    

Assemblies and Deployment

Assembly Types:


// Assembly attributes example
[assembly: AssemblyTitle("MyApplication")]
[assembly: AssemblyDescription("Sample Application")]
[assembly: AssemblyCompany("My Company")]
[assembly: AssemblyProduct("My Product")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyVersion("1.0.0.0")]

// Strong naming
// sn -k keyfile.snk
[assembly: AssemblyKeyFile("keyfile.snk")]
    

Application Frameworks

Major Frameworks:


// WPF Example
<Window x:Class="MyApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Button Content="Click Me"
                Click="Button_Click"
                Width="100" Height="30"/>
    </Grid>
</Window>

// WCF Service Example
[ServiceContract]
public interface IUserService
{
    [OperationContract]
    User GetUser(int userId);
}

public class UserService : IUserService
{
    public User GetUser(int userId)
    {
        // Implementation
        return new User { Id = userId };
    }
}
    

Development Tools

Best Practices

Development Guidelines:


// Best practices example
public class BestPracticesDemo : IDisposable
{
    private readonly ILogger _logger;
    private bool _disposed;

    public BestPracticesDemo(ILogger logger)
    {
        _logger = logger ?? throw new ArgumentNullException(nameof(logger));
    }

    public async Task ProcessDataAsync(string input)
    {
        try
        {
            _logger.LogInformation("Processing data");
            await ValidateInputAsync(input);
            // Process data
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Error processing data");
            throw;
        }
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    protected virtual void Dispose(bool disposing)
    {
        if (!_disposed)
        {
            if (disposing)
            {
                // Clean up managed resources
            }
            // Clean up unmanaged resources
            _disposed = true;
        }
    }
}
    

Related Resources