Core Concepts of .NET Framework 3.5
The .NET Framework 3.5 introduces significant new features and enhancements built upon the foundation of previous versions. Understanding its core concepts is crucial for developing robust and scalable applications.
Common Language Runtime (CLR)
The CLR is the execution engine of the .NET Framework. It provides essential services such as:
- Memory Management: Automatic garbage collection to handle memory allocation and deallocation.
- Type Safety: Ensures that code written in different .NET languages can interoperate safely.
- Security: Manages code access security (CAS) and other security policies.
- Exception Handling: A structured way to handle runtime errors.
- Just-In-Time (JIT) Compilation: Compiles Intermediate Language (IL) code into native machine code at runtime.
Base Class Library (BCL)
The BCL, also known as the Framework Class Library (FCL), is a comprehensive set of reusable, object-oriented types that can be used to develop a wide range of applications. Key namespaces include:
System
: Fundamental classes and base types.System.Collections
: Interfaces and classes that define collections of objects.System.IO
: Classes for reading and writing files and streams.System.Net
: Classes for network programming.System.Xml
: Classes for working with XML documents.System.Windows.Forms
andSystem.Web
: For UI development (Windows Forms and ASP.NET respectively).
Intermediate Language (IL)
When you compile code written in a .NET language (like C# or VB.NET), it is compiled into Intermediate Language (IL), also known as Microsoft Intermediate Language (MSIL). This IL code is platform-independent and is later compiled into native machine code by the CLR's JIT compiler.
Benefits of IL:
- Language Interoperability: Code written in different .NET languages can call each other seamlessly.
- Platform Independence: IL can run on any platform that has a compatible CLR implementation.
Common Type System (CTS)
The CTS defines a set of types and operations that all .NET languages can support. This ensures that objects created by different languages can be understood and used by each other. The CLR enforces the CTS.
Common Language Specification (CLS)
The CLS is a set of guidelines that languages must follow to ensure they can interoperate with other CLS-compliant languages. Adhering to the CLS is crucial for creating libraries that can be used by developers using different .NET languages.
Application Models Introduced/Enhanced in 3.5
.NET Framework 3.5 builds upon existing models and introduces new ones:
- Windows Communication Foundation (WCF): A unified programming model for building service-oriented applications.
- Windows Presentation Foundation (WPF): A UI framework for building rich, client-side applications with a focus on graphics and multimedia.
- Windows Workflow Foundation (WF): A platform for building workflow-enabled applications.
- LINQ (Language Integrated Query): A powerful feature that adds native data querying capabilities to .NET languages, enabling querying of objects, databases, XML, and more.
- ASP.NET AJAX: For building dynamic and interactive web applications.
LINQ in Action:
LINQ provides a consistent syntax for querying various data sources. For example, querying a list of numbers:
var numbers = new int[] { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
var evenNumbers = from num in numbers
where num % 2 == 0
orderby num
select num;
foreach (var n in evenNumbers)
{
Console.WriteLine(n);
}
Managed Code vs. Unmanaged Code
Code that runs under the control of the CLR is called managed code. It benefits from CLR services like garbage collection and security. Code that runs directly on the operating system without CLR services is called unmanaged code (e.g., C++ applications not using the .NET Framework).
Understanding these fundamental concepts will provide a solid foundation for exploring the specific features and APIs of the .NET Framework 3.5.