Unit 1: Introduction To .Net And C#
I. Orientation — The .NET Development Ecosystem
.NET is Microsoft’s open-source, cross-platform development platform, while C# is its principal general-purpose programming language. ASP.NET Core is the framework within .NET used to create web applications, REST APIs, real-time services, and cloud-based systems.
- Core principle: .NET separates source-language development from runtime execution; C# code is compiled into Intermediate Language and executed by the Common Language Runtime.
- Main components:
- Runtime: Executes applications, manages memory, and provides services such as garbage collection and exception handling.
- Libraries: Supply reusable types for collections, files, networking, databases, and web development.
- SDK: Contains compilers, templates, build tools, and the .NET CLI.
- Application frameworks: Include ASP.NET Core for web applications and libraries for console, desktop, cloud, and mobile development.
- Major characteristics: Cross-platform operation, strong typing, managed execution, language interoperability, dependency injection, asynchronous programming, and package-based extensibility.
- Development flow: Write C# source code, restore dependencies, compile the project, and run the generated application through the .NET runtime.
II. ASP.NET Core — Modern Web Application Framework
A. Introduction to ASP.NET Core and its features
ASP.NET Core is an open-source, high-performance framework for building modern web applications and services on Windows, Linux, and macOS.
- Cross-platform support: An ASP.NET Core application can be developed and hosted on multiple operating systems using the same project structure.
- Open-source development: The framework and runtime are maintained publicly under the .NET organization, allowing community participation and transparent releases.
- High performance: ASP.NET Core uses an optimized web server named Kestrel, which processes HTTP requests directly or operates behind IIS, Nginx, or Apache.
- Unified web framework: It supports several programming models:
- MVC: Separates models, views, and controllers.
- Razor Pages: Organizes server-rendered pages around page-specific handlers.
- Web API: Creates HTTP services, commonly returning JSON.
- Minimal APIs: Defines lightweight endpoints with little setup.
- SignalR: Provides real-time server-to-client communication.
- Middleware pipeline: Requests pass through ordered middleware components for functions such as authentication, routing, error handling, and static-file delivery.
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Hello, ASP.NET Core!");
app.Run();- Built-in dependency injection: Services are registered in
builder.Servicesand supplied to classes that require them, reducing tight coupling. - Configuration support: Settings may come from
appsettings.json, environment variables, command-line arguments, or secret stores. - Environment awareness: Development, staging, and production environments can use different configurations and error-handling behavior.
- Cloud and container readiness: ASP.NET Core works effectively with Docker, microservices, reverse proxies, and cloud deployment platforms.
B. ASP.NET Core Version History
ASP.NET Core evolved from a redesigned alternative to classic ASP.NET into the unified web framework of modern .NET.
- ASP.NET 5 period, 2014–2016: Microsoft initially used the name ASP.NET 5 but renamed the framework ASP.NET Core to emphasize that it was a redesign rather than a direct continuation.
- ASP.NET Core 1.0, 2016: Introduced the cross-platform, modular framework with Kestrel and command-line tooling.
- ASP.NET Core 2.x, 2017–2018: Expanded APIs and introduced Razor Pages in version 2.0, making page-focused web development simpler.
- ASP.NET Core 3.0 and 3.1, 2019: Added endpoint routing and strengthened support for Blazor; version 3.1 was a Long-Term Support release.
- ASP.NET Core 5.0, 2020: The word “Core” was removed from the general platform name
.NET Core, but retained in ASP.NET Core to distinguish it from classic ASP.NET. - ASP.NET Core 6.0, 2021: Introduced Minimal APIs and supported C# 10 features such as global
usingdirectives. - ASP.NET Core 7.0, 2022: Improved Minimal APIs, performance, rate limiting, and HTTP support.
- ASP.NET Core 8.0, 2023: An LTS release that expanded Blazor’s server-side rendering and introduced stronger identity and cloud-native capabilities.
- ASP.NET Core 9.0, 2024: Improved performance, OpenAPI generation, security, diagnostics, and cloud-oriented development.
- Release model: Major .NET and ASP.NET Core versions follow an annual cycle; LTS releases receive longer support than Standard Term Support releases.
III. The .NET Platform — Runtime, Libraries, and Compatibility
A. Difference Between .NET Framework and .NET Core
.NET Framework and .NET Core belong to the same technology family but differ in platform support, deployment, architecture, and development purpose.
-
.NET Framework:
- Platform: Primarily Windows-only and closely integrated with Windows.
- Release history: Introduced in 2002; version 4.8.1 represents its mature maintenance line.
- Application types: Commonly supports ASP.NET Web Forms, older ASP.NET MVC applications, Windows Forms, WPF, and Windows services.
- Installation model: Usually installed at the operating-system level, so applications may share the installed framework.
- Use case: Appropriate mainly for maintaining existing Windows applications that depend on Framework-specific technologies.
-
.NET Core and modern .NET:
- Platform: Runs on Windows, Linux, and macOS.
- Release history:
.NET Coreversions 1.0–3.1 were followed by the unified name.NET, beginning with .NET 5. - Architecture: Modular and distributed through SDKs, runtimes, framework references, and NuGet packages.
- Deployment model: Supports framework-dependent and self-contained deployment.
- Use case: Preferred for new web, cloud, containerized, console, service, and cross-platform applications.
- Compatibility point: Both use managed code and CLR concepts, but Framework-only APIs such as Web Forms are not automatically available in modern .NET.
B. Overview of the .NET Core Platform
The .NET Core platform consists of the runtime, libraries, SDK, language tools, and application frameworks required to develop and execute applications.
- CoreCLR: Implements managed execution, Just-In-Time compilation, garbage collection, thread handling, and exception processing.
- Base Class Library: Provides fundamental types such as
String,DateTime,List<T>,File, andHttpClient. - SDK: Includes the Roslyn C# compiler, MSBuild, project templates, and command-line tools.
- Project system: A
.csprojXML file defines the target framework, dependencies, and build settings.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
</Project>- NuGet: The package manager obtains external libraries and records dependencies in the project file.
- Target Framework Moniker: A value such as
net8.0identifies the API set against which the application is compiled. - Deployment choices:
- Framework-dependent: Requires a compatible runtime on the target computer.
- Self-contained: Packages the runtime with the application, increasing deployment size but reducing external requirements.
IV. Development Tooling — VS Code and the .NET CLI
A. Setting up a development environment with VS Code
VS Code provides a lightweight, cross-platform environment for editing, building, debugging, and running .NET projects.
- Install the SDK: Install a supported .NET SDK and verify it with
dotnet --version; the SDK includes the runtime and CLI. - Install VS Code: Use the official build for Windows, Linux, or macOS.
- Install extensions: Add C# Dev Kit and its associated C# language support for IntelliSense, project navigation, testing, and debugging.
- Create a workspace:
mkdir FirstApp
cd FirstApp
dotnet new console
code .- Run the project: Execute
dotnet runin the integrated terminal or use the editor’s Run and Debug interface. - Debugging facilities: Breakpoints pause execution; the Variables, Watch, Call Stack, and Debug Console views help inspect program state.
- Configuration check: Running
dotnet --infodisplays installed SDKs, runtimes, operating-system details, and environment information.
B. Introduction to .NET CLI and .NET CLI Commands
The .NET Command-Line Interface is a platform-independent toolchain for creating, restoring, building, testing, running, and publishing .NET applications.
- Command structure: Commands generally follow
dotnet <command> [arguments] [options]. - Environment commands:
dotnet --version: Shows the active SDK version.dotnet --info: Displays detailed environment information.dotnet --list-sdks: Lists installed SDKs.
- Project commands:
dotnet new console: Creates a console project.dotnet restore: Downloads required NuGet packages.dotnet build: Compiles the project and reports errors.dotnet run: Builds and executes the application.dotnet test: Runs tests in a test project.dotnet publish -c Release: Produces deployment-ready output.
- Dependency commands:
dotnet add package PackageNameadds a NuGet package, whiledotnet remove package PackageNameremoves it. - Typical workflow:
dotnet new webapi -n ProductApi
cd ProductApi
dotnet restore
dotnet build
dotnet runV. C# — Language, Evolution, and Execution
A. Introduction to C
C# is a modern, statically typed, object-oriented programming language designed by Microsoft for the .NET platform.
- Strong typing: Variables have defined types, allowing many errors to be detected during compilation.
- Object orientation: Classes combine state and behavior and support encapsulation, inheritance, and polymorphism.
- Managed programming: The runtime handles memory through garbage collection rather than requiring routine manual deallocation.
- Language capabilities: C# supports generics, delegates, events, lambda expressions, LINQ, pattern matching, and asynchronous programming.
- Basic program:
string name = "Asha";
int marks = 85;
Console.WriteLine($"{name}: {marks}");- Concrete elements:
stringandintare types,nameandmarksare variables, and$"..."is an interpolated string. - Case sensitivity:
marks,Marks, andMARKSare different identifiers. - Entry point: Modern projects may use top-level statements; traditional applications begin with a
static Mainmethod.
B. History of C# Version
C# versions have progressively added safer syntax, abstraction mechanisms, and more concise programming features.
- C# 1.0, 2002: Established classes, interfaces, delegates, properties, and managed object-oriented programming.
- C# 2.0, 2005: Added generics, nullable value types, anonymous methods, and iterators.
- C# 3.0, 2007: Introduced LINQ, lambda expressions, extension methods, and anonymous types.
- C# 4.0, 2010: Added
dynamic, named arguments, and optional arguments. - C# 5.0, 2012: Introduced
asyncandawaitfor asynchronous operations. - C# 6–8, 2015–2019: Added string interpolation, local functions, tuples, nullable reference types, and switch expressions.
- C# 9–10, 2020–2021: Added records, top-level statements, global
usingdirectives, and file-scoped namespaces. - C# 11–13, 2022–2024: Added raw string literals, required members, primary constructors, collection expressions, and further performance-oriented features.
- Version relationship: New C# versions normally accompany new .NET SDK releases, while project settings can restrict the selected language version.
C. C# Code Execution
C# execution uses compilation and managed runtime services rather than directly executing source code.
- Compilation stage: The Roslyn compiler converts
.cssource files into Common Intermediate Language, or CIL, stored in an assembly such as.dll. - Metadata stage: The assembly records type definitions, method signatures, references, and version information.
- Loading stage: The CLR loads the assembly and resolves required framework and package dependencies.
- JIT stage: The Just-In-Time compiler translates required CIL methods into native machine instructions for the current processor.
- Runtime services: The CLR provides garbage collection, exception handling, type safety, threading, and diagnostics.
- Execution sequence:
C# source → Roslyn compiler → CIL assembly → CLR/JIT → Native execution- Build output:
dotnet buildnormally places compiled files underbin/Debug/<target-framework>/.
D. Installing and Configuring C# in Visual Studio
Visual Studio supplies an integrated Windows development environment containing editors, compilers, designers, debugging tools, and project templates.
- Installation: Download the Visual Studio Installer and select a supported edition, such as Community.
- Workload selection:
- ASP.NET and web development: Installs tools for ASP.NET Core, web APIs, Razor, and web publishing.
- .NET desktop development: Installs tools for console, Windows Forms, and WPF applications.
- Component configuration: Confirm that the required .NET SDK, targeting packs, and optional database or container tools are selected.
- Project creation: Choose Create a new project, select a template such as Console App or ASP.NET Core Web API, and specify the project name, location, and target framework.
- Development support: IntelliSense offers completion and type information, while Solution Explorer organizes projects, dependencies, and source files.
- Build and execution:
Ctrl+Shift+Bbuilds the solution;F5runs with debugging, andCtrl+F5runs without the debugger. - SDK verification: The project’s target framework appears in project properties and in the
.csprojfile, for example<TargetFramework>net8.0</TargetFramework>.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →