Unit 1: Introduction To .Net And C# - Subjective Questions
INT402 — Modern Web Programming Tools And Techniques • Practice Questions with Detailed Answers
20 questions
Define ASP.NET Core and explain its major features.
ASP.NET Core is an open-source, cross-platform framework developed by Microsoft for building modern web applications, REST APIs, cloud-based services, and real-time applications.
Major features:
- Cross-platform support: Applications can run on Windows, Linux, and macOS.
- Open-source: Its source code is publicly available and developed through community participation.
- High performance: It provides an optimized and lightweight request-processing pipeline.
- Modular architecture: Developers can include only the packages required by an application.
- Built-in dependency injection: Services can be registered and injected into application components.
- Unified development model: It supports MVC applications, Razor Pages, Web APIs, Minimal APIs, and Blazor.
- Middleware pipeline: HTTP requests and responses are processed through configurable middleware components.
- Configuration support: Configuration can be loaded from JSON files, environment variables, command-line arguments, and other sources.
- Cloud readiness: It supports containerization, microservices, logging, health checks, and environment-based configuration.
- Side-by-side versioning: Different applications can use different .NET runtime versions on the same computer.
Describe the architecture and request-processing pipeline of an ASP.NET Core application.
An ASP.NET Core application processes HTTP requests through a configurable middleware pipeline.
Main architectural elements:
- Web server: Kestrel receives HTTP requests. A reverse proxy such as IIS, Nginx, or Apache may be placed in front of Kestrel.
- Program entry point: The
Program.csfile creates the application builder, registers services, configures middleware, and starts the application. - Service container: Required services are registered in the built-in dependency injection container.
- Middleware: Middleware components perform tasks such as exception handling, HTTPS redirection, authentication, authorization, static-file handling, and routing.
- Routing: The routing system maps an incoming URL to an endpoint such as a controller action, Razor Page, or Minimal API handler.
- Endpoint: The selected endpoint executes application logic and produces a response.
Request flow:
- The client sends an HTTP request.
- Kestrel receives the request.
- The request passes through middleware in registration order.
- Routing selects a matching endpoint.
- The endpoint executes and creates a response.
- The response passes back through the middleware in reverse order.
- Kestrel returns the response to the client.
Each middleware component can process the request, pass it to the next component, modify the response, or terminate the pipeline early.
Summarize the important stages in the version history of ASP.NET Core.
The development of ASP.NET Core reflects Microsoft's transition from the Windows-dependent ASP.NET Framework to a modern cross-platform web framework.
Important stages:
- ASP.NET Core 1.0: Released in 2016 as a redesigned, open-source, cross-platform framework. It introduced a modular architecture and middleware-based pipeline.
- ASP.NET Core 2.0: Expanded the available APIs through .NET Standard 2.0 and simplified application development.
- ASP.NET Core 2.1: Introduced improvements such as HTTPS-by-default, Razor Class Libraries, SignalR, and the generic host.
- ASP.NET Core 2.2: Added endpoint-routing foundations and performance improvements.
- ASP.NET Core 3.0: Discontinued support for the old .NET Framework target and introduced Blazor Server, improved endpoint routing, and gRPC support.
- ASP.NET Core 3.1: Became a Long-Term Support release focused on stability.
- ASP.NET Core on .NET 5: The word
Corewas removed from the main .NET platform name, although the web framework continued to be called ASP.NET Core. - ASP.NET Core on .NET 6: Added Minimal APIs, improved performance, and simplified application startup. It was an LTS release.
- ASP.NET Core on .NET 7: Improved Minimal APIs, rate limiting, performance, and cloud-native development.
- ASP.NET Core on .NET 8: An LTS release that enhanced Blazor, Native AOT support, Minimal APIs, and performance.
- ASP.NET Core on .NET 9: Continued improvements in performance, cloud-native development, security, and developer productivity.
ASP.NET Core versions generally follow the annual .NET release cycle, with selected releases receiving Long-Term Support.
Distinguish between .NET Framework and modern .NET Core/.NET.
.NET Framework and .NET Core, now called modern .NET, differ in platform support, deployment, architecture, and intended use.
| Basis | .NET Framework | .NET Core / Modern .NET |
|---|---|---|
| Platform | Primarily Windows | Windows, Linux, and macOS |
| Source model | Some components are open-source | Open-source and community-driven |
| Application types | ASP.NET, Windows Forms, WPF, and enterprise Windows applications | Web applications, APIs, cloud services, console applications, desktop applications, mobile applications, and microservices |
| Deployment | Usually machine-wide | Supports framework-dependent and self-contained deployment |
| Versioning | Generally installed system-wide | Supports side-by-side runtime versions |
| Performance | Suitable for traditional Windows applications | Optimized for high-performance and cloud workloads |
| Architecture | Large and relatively monolithic | Modular and package-based |
| Command-line tools | Primarily Visual Studio-based tools | Includes the cross-platform dotnet CLI |
| Web framework | Uses classic ASP.NET | Uses ASP.NET Core |
| Future development | Mainly receives maintenance and security fixes | Primary platform for new .NET development |
Conclusion: .NET Framework remains useful for existing Windows-specific applications, while modern .NET is preferred for new, cross-platform, scalable, and cloud-oriented applications.
Explain the components of the .NET Core platform and the role played by each component.
The .NET Core platform, now part of modern .NET, consists of several components that work together to build and execute applications.
- .NET Runtime: Executes managed applications and provides services such as garbage collection, exception handling, thread management, and type safety.
- CoreCLR: The original runtime implementation used by .NET Core. It includes the execution engine and Just-In-Time compiler.
- Base Class Library: Provides reusable types for strings, collections, files, networking, dates, tasks, and other common operations.
- CoreFX: The historical name for the foundational libraries of .NET Core.
- SDK: Contains the tools required to create, restore, build, test, publish, and package applications.
dotnetCLI: Provides cross-platform commands for managing projects and executing applications.- Roslyn compiler: Compiles C# and Visual Basic source code into Common Intermediate Language.
- NuGet: Manages third-party and Microsoft packages required by projects.
- Application frameworks: ASP.NET Core, Entity Framework Core, and other frameworks provide support for specialized application development.
- Host: Selects and starts the appropriate runtime before executing an application.
Together, these components offer a modular, cross-platform environment for application development and execution.
Describe the steps required to set up a .NET development environment using Visual Studio Code.
The following steps can be used to set up .NET development in Visual Studio Code:
-
Install the .NET SDK:
- Download the SDK from the official .NET website.
- Select the installer for Windows, Linux, or macOS.
- The SDK includes the runtime, compiler, libraries, and
dotnetCLI.
-
Verify the installation:
- Open a terminal and execute
dotnet --version. - Use
dotnet --infoto view detailed SDK and runtime information.
- Open a terminal and execute
-
Install Visual Studio Code:
- Download and install VS Code from its official website.
-
Install C# support:
- Open the Extensions view in VS Code.
- Install C# Dev Kit and the recommended C# extension from Microsoft.
-
Create a project:
- Run
dotnet new console -n SampleAppfor a console application. - Alternatively, run
dotnet new webapp -n SampleWebAppfor a Razor Pages application.
- Run
-
Open the project:
- Execute
cd SampleAppfollowed bycode ..
- Execute
-
Restore and build:
- Run
dotnet restoreanddotnet build.
- Run
-
Run the application:
- Execute
dotnet run.
- Execute
-
Configure debugging:
- Open the Run and Debug view.
- Allow VS Code to create the required launch configuration when prompted.
- Set breakpoints and start debugging.
The environment is then ready for writing, building, running, and debugging C# applications.
What is the .NET CLI? Explain its general command syntax and advantages.
The .NET Command-Line Interface, or .NET CLI, is a cross-platform toolchain used to create, build, run, test, package, and publish .NET applications.
General syntax:
dotnet <command> [arguments] [options]
For example, dotnet build MyApp.csproj --configuration Release builds the specified project in Release mode.
Main uses:
- Creating projects from templates
- Restoring NuGet packages
- Compiling source code
- Running applications
- Executing automated tests
- Adding package and project references
- Publishing deployable applications
- Managing development tools
Advantages:
- Cross-platform: It works on Windows, Linux, and macOS.
- Automation-friendly: Commands can be used in scripts and CI/CD pipelines.
- Consistent workflow: The same commands work across supported operating systems.
- Editor independence: It can be used with VS Code, Visual Studio, or any text editor.
- Template support: It provides built-in templates for console, web, class-library, test, and other projects.
- Extensibility: Additional global or local .NET tools can be installed.
The CLI is especially useful for lightweight development environments, server automation, and cloud-based build processes.
Explain the purpose and usage of important .NET CLI commands.
Important .NET CLI commands include:
dotnet --info: Displays installed SDKs, runtimes, operating-system information, and environment details.dotnet --version: Displays the version of the SDK currently selected.dotnet new: Creates a project or file from a template. Example:dotnet new console -n DemoApp.dotnet restore: Downloads and restores NuGet packages listed in a project.dotnet build: Restores dependencies when necessary and compiles the project.dotnet run: Builds and runs a project from its source code.dotnet test: Builds test projects and executes their tests.dotnet clean: Removes files generated by previous builds.dotnet publish: Produces deployment-ready files.dotnet add package: Adds a NuGet package reference to a project.dotnet add reference: Adds a reference from one project to another.dotnet remove: Removes a package or project reference.dotnet sln: Adds, removes, or lists projects in a solution file.dotnet pack: Creates a NuGet package from a project.dotnet watch: Monitors source files and reruns or rebuilds the application when changes occur.
A typical workflow is dotnet new, followed by dotnet restore, dotnet build, dotnet run, dotnet test, and finally dotnet publish.
Differentiate between the .NET SDK, .NET runtime, and ASP.NET Core runtime.
The SDK and runtimes serve different purposes in .NET development.
-
.NET SDK:
- Used to develop .NET applications.
- Includes the .NET CLI, compilers, build tools, templates, and libraries.
- Also includes a compatible .NET runtime.
- Required on a developer's computer or build server.
-
.NET runtime:
- Used to execute ordinary .NET applications.
- Includes the runtime engine and base libraries.
- Does not contain all project-creation and compilation tools supplied by the SDK.
- Suitable for a machine that only needs to run an already-built application.
-
ASP.NET Core runtime:
- Used to run ASP.NET Core web applications.
- Includes the .NET runtime and ASP.NET Core shared framework.
- Required for framework-dependent ASP.NET Core deployments when the server does not already have the required runtime.
In summary: A developer normally installs the SDK, while an application server may need only the appropriate runtime. A self-contained deployment can package the required runtime with the application.
Define C# and discuss its important characteristics and applications.
C#, pronounced C-Sharp, is a modern, general-purpose, object-oriented programming language developed by Microsoft for the .NET platform. It was designed by a team led by Anders Hejlsberg.
Important characteristics:
- Object-oriented: Supports classes, objects, inheritance, polymorphism, abstraction, and encapsulation.
- Strongly typed: Type rules are checked to reduce invalid operations and improve reliability.
- Managed execution: Programs execute under the .NET runtime, which manages memory and other resources.
- Automatic memory management: Garbage collection automatically reclaims unreachable managed objects.
- Component-oriented: Properties, events, attributes, and interfaces support reusable components.
- Modern syntax: It provides generics, delegates, lambda expressions, LINQ, pattern matching, records, and asynchronous programming.
- Exception handling: Structured exception handling uses
try,catch,finally, andthrow. - Cross-platform support: Modern C# applications can run on Windows, Linux, and macOS through .NET.
Applications of C#:
- ASP.NET Core web applications and APIs
- Desktop applications
- Cloud services and microservices
- Mobile and cross-platform applications
- Games developed with Unity
- Console applications and command-line tools
- Enterprise and database applications
- Internet of Things applications
Trace the history and evolution of major C# language versions.
C# has evolved continuously by adding features that improve type safety, expressiveness, performance, and developer productivity.
- C# 1.0: Introduced classes, structs, interfaces, delegates, events, properties, and managed execution.
- C# 2.0: Added generics, nullable value types, anonymous methods, iterators, and partial classes.
- C# 3.0: Introduced LINQ, lambda expressions, extension methods, anonymous types, object initializers, and implicitly typed local variables.
- C# 4.0: Added dynamic binding, named arguments, optional parameters, and generic variance.
- C# 5.0: Introduced the
asyncandawaitkeywords for asynchronous programming. - C# 6.0: Added string interpolation, null-conditional operators, expression-bodied members, and exception filters.
- C# 7.x: Added tuples, pattern matching, local functions,
outvariables, and other performance-related features. - C# 8.0: Introduced nullable reference types, switch expressions, ranges and indices, asynchronous streams, and default interface members.
- C# 9.0: Added records, top-level statements, init-only setters, and enhanced pattern matching.
- C# 10: Added global
usingdirectives, file-scoped namespaces, record structs, and improvements to lambda expressions. - C# 11: Added raw string literals, required members, generic math support, and list-pattern-related improvements.
- C# 12: Introduced primary constructors for classes and structs, collection expressions, and additional lambda improvements.
- C# 13: Added further improvements involving
paramscollections, locking, partial members, and performance-oriented language capabilities.
The language version normally advances with new .NET releases, although the compiler can be configured to use a specific supported language version.
Explain the complete execution process of a C# program from source code to machine-level execution.
The execution of a C# program occurs in multiple stages:
-
Writing source code:
- The developer writes C# statements in files with the
.csextension.
- The developer writes C# statements in files with the
-
Compilation:
- The Roslyn C# compiler checks syntax, type rules, and language semantics.
- Valid source code is compiled into Common Intermediate Language, also called CIL or IL.
- The compiler also generates metadata describing types, members, and references.
-
Assembly generation:
- IL and metadata are stored in an assembly, usually a
.dllor.exefile. - The assembly also contains a manifest describing its identity, version, and dependencies.
- IL and metadata are stored in an assembly, usually a
-
Runtime loading:
- The .NET host selects the required runtime.
- The runtime loads the assembly and resolves its dependencies.
-
Type verification and runtime services:
- The runtime enforces type safety and provides exception handling, security-related checks, threading, and garbage collection.
-
Machine-code generation:
- The Just-In-Time compiler converts required IL methods into native machine code during execution.
- Alternatively, Ahead-Of-Time compilation may generate native code before normal execution.
-
Execution:
- The processor executes the generated native instructions.
- The garbage collector automatically manages memory occupied by managed objects.
Therefore, the simplified flow is: C# source code → compiler → IL and metadata → assembly → runtime/JIT or AOT → native machine code → execution.
Explain the terms CLR, CIL, JIT, CTS, CLS, and managed code in the context of C# execution.
-
CLR — Common Language Runtime: The execution environment of .NET. It manages program execution, memory, exceptions, threads, garbage collection, and type safety.
-
CIL — Common Intermediate Language: A CPU-independent instruction set generated when C# code is compiled. It is also commonly called IL.
-
JIT — Just-In-Time compiler: A runtime compiler that converts CIL methods into native machine code when they are needed for execution.
-
CTS — Common Type System: Defines how types are declared, used, and managed by .NET. It allows different .NET languages to share compatible types.
-
CLS — Common Language Specification: A set of rules that language designers and library developers follow to ensure interoperability among .NET languages. The CLS is a compatible subset of CTS rules.
-
Managed code: Code whose execution is controlled by the .NET runtime. It receives runtime services such as garbage collection, exception handling, and type checking.
These mechanisms allow C# programs to be portable across supported platforms while maintaining type safety and language interoperability.
Compare Just-In-Time compilation and Ahead-Of-Time compilation in .NET.
Just-In-Time compilation and Ahead-Of-Time compilation convert .NET code into native machine code at different times.
| Basis | JIT Compilation | AOT Compilation |
|---|---|---|
| Compilation time | During application execution | Before the application executes |
| Input | IL contained in assemblies | Application IL and related metadata |
| Startup | May involve runtime compilation overhead | Can provide faster startup |
| Optimization | Can optimize using runtime information | Optimizes primarily at build or publish time |
| Deployment size | Framework-dependent applications can be relatively small | Native AOT output may include required native components |
| Dynamic features | Broad support for reflection and dynamic code | Some dynamic features may require configuration or may be limited |
| Runtime dependency | Normally requires a compatible runtime unless packaged | Native AOT can produce a self-contained native executable |
| Typical usage | General-purpose .NET applications | Command-line tools, microservices, serverless functions, and startup-sensitive applications |
JIT process: IL is loaded and individual methods are compiled when required. The generated native code is then executed.
AOT process: Native code is generated during publishing or a prior compilation stage, reducing the amount of compilation required at runtime.
The preferred approach depends on startup time, deployment size, platform restrictions, dynamic-code requirements, and performance goals.
Describe how to install and configure C# development support in Microsoft Visual Studio.
C# development support can be installed and configured in Visual Studio as follows:
-
Download Visual Studio:
- Obtain the Visual Studio Installer from Microsoft's official website.
- Choose an appropriate edition such as Community, Professional, or Enterprise.
-
Select workloads:
- Choose .NET desktop development for console, Windows Forms, and WPF applications.
- Choose ASP.NET and web development for ASP.NET Core applications and APIs.
- Select other workloads if mobile, cloud, data, or game development is required.
-
Select individual components:
- Verify that the required .NET SDK, runtime, targeting packs, and development tools are selected.
-
Install Visual Studio:
- Start the installation and restart the computer if requested.
-
Create a project:
- Open Visual Studio and select Create a new project.
- Choose a template such as Console App, ASP.NET Core Web App, or Class Library.
- Enter the project name, location, framework version, and other options.
-
Configure the project:
- Use project properties to choose the target framework, build configuration, nullable-reference settings, and startup behavior.
-
Build and run:
- Use Build Solution to compile the solution.
- Run with debugging using
F5or without debugging usingCtrl+F5.
-
Verify debugging:
- Set breakpoints, inspect variables, use the Watch window, and examine the call stack.
Visual Studio provides IntelliSense, refactoring, NuGet management, testing, profiling, and graphical debugging for C# projects.
Explain the structure of a basic C# console application and the function of its major elements.
A traditional C# console application may contain the following structure:
using System;
namespace SampleApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
}
Explanation:
using System;: Makes types in theSystemnamespace available without writing their fully qualified names.- Namespace: Groups related types and helps prevent naming conflicts.
- Class: Defines a reference type that contains data and behavior. Here,
Programcontains the entry method. Mainmethod: Serves as the traditional entry point of the application.static: AllowsMainto run without first creating an object ofProgram.void: Indicates that the method does not return a value.Mainmay also return an integer exit code.string[] args: Receives command-line arguments.Console.WriteLine: Writes a line of text to the standard output.
Modern C# also supports top-level statements, allowing a simple program to be written as Console.WriteLine("Hello, World!"); without explicitly declaring Main or Program.
Explain project files, solution files, and NuGet package management in .NET development.
Project files:
- A C# project commonly uses a
.csprojfile. - It is an XML-based file that specifies the SDK, target framework, package references, project references, compiler settings, and build properties.
- SDK-style projects automatically include many source files from the project directory.
A simple project file may define a target framework such as net8.0, the output type, implicit using directives, and nullable-reference behavior.
Solution files:
- A
.slnfile groups one or more related projects. - It helps manage applications containing web, library, test, and supporting projects.
- The CLI can create a solution with
dotnet new slnand add a project withdotnet sln add.
NuGet package management:
- NuGet is the package manager for .NET.
- Package references are normally stored in the project file.
dotnet add package <PackageName>adds a package reference.dotnet restoredownloads required packages and resolves dependencies.- Visual Studio and VS Code extensions can also provide graphical package-management features.
Together, project files, solutions, and NuGet packages organize source code, dependencies, configuration, and build operations.
Compare framework-dependent deployment and self-contained deployment in .NET.
.NET applications can be deployed mainly as framework-dependent or self-contained applications.
| Basis | Framework-Dependent Deployment | Self-Contained Deployment |
|---|---|---|
| Runtime inclusion | Does not include the complete .NET runtime | Includes the required .NET runtime |
| Target machine | Must have a compatible runtime installed | Does not require a separately installed runtime |
| Deployment size | Usually smaller | Usually larger |
| Runtime updates | Shared runtime can be updated centrally | A new application version must normally be published to include runtime updates |
| Platform targeting | Can be relatively portable when compatible runtimes exist | Published for a specific runtime identifier, such as Windows or Linux |
| Version control | Uses an installed compatible runtime according to configuration | Application carries its selected runtime version |
| Best suited for | Managed servers with shared runtime installations | Isolated systems, controlled deployments, and machines without .NET |
Publishing examples:
- A normal
dotnet publishcommonly produces a framework-dependent deployment. - Supplying a runtime identifier and enabling self-contained publishing produces platform-specific output containing the runtime.
The deployment model should be selected according to application size, server control, runtime availability, update policy, and platform requirements.
Explain the role of dependency injection, configuration, and logging in ASP.NET Core.
ASP.NET Core includes built-in support for dependency injection, configuration, and logging.
Dependency injection:
- Services are registered in the application's service collection.
- Components request services through constructors or method parameters rather than creating tightly coupled objects.
- Common lifetimes are Transient, Scoped, and Singleton.
- It improves testability, modularity, and maintainability.
Configuration:
- Configuration values can be read from
appsettings.json, environment-specific JSON files, environment variables, command-line arguments, user secrets, and external providers. - Providers are combined into a configuration system, with later providers generally able to override earlier values.
- Strongly typed settings can be represented using the options pattern.
Logging:
- ASP.NET Core provides a common logging abstraction.
- Applications can log messages using categories and levels such as Trace, Debug, Information, Warning, Error, and Critical.
- Providers can send logs to the console, debug output, event logs, or external monitoring platforms.
- Structured logging allows values to be stored as searchable properties.
These three services reduce boilerplate code and support testable, configurable, and observable web applications.
Describe how to create, build, run, test, and publish a .NET application using only the .NET CLI.
A complete command-line workflow can be performed as follows:
-
Create a solution:
- Run
dotnet new sln -n ProductSolution.
- Run
-
Create an application project:
- Run
dotnet new console -n ProductApp.
- Run
-
Create a test project:
- Run
dotnet new xunit -n ProductApp.Tests.
- Run
-
Add projects to the solution:
- Run
dotnet sln ProductSolution.sln add ProductApp/ProductApp.csproj. - Add the test project in the same way.
- Run
-
Add a project reference:
- Run
dotnet add ProductApp.Tests/ProductApp.Tests.csproj reference ProductApp/ProductApp.csproj.
- Run
-
Restore packages:
- Run
dotnet restore ProductSolution.sln.
- Run
-
Build the solution:
- Run
dotnet build ProductSolution.sln. - Use
--configuration Releasefor an optimized release build.
- Run
-
Run the application:
- Run
dotnet run --project ProductApp/ProductApp.csproj.
- Run
-
Execute tests:
- Run
dotnet test ProductSolution.sln.
- Run
-
Publish the application:
- Run
dotnet publish ProductApp/ProductApp.csproj --configuration Release --output publish.
- Run
-
Clean generated files when required:
- Run
dotnet clean ProductSolution.sln.
- Run
This workflow is cross-platform and can be placed in shell scripts or continuous integration pipelines.
Define ASP.NET Core and explain its major features.
ASP.NET Core is an open-source, cross-platform framework developed by Microsoft for building modern web applications, REST APIs, cloud-based services, and real-time applications.
Major features:
- Cross-platform support: Applications can run on Windows, Linux, and macOS.
- Open-source: Its source code is publicly available and developed through community participation.
- High performance: It provides an optimized and lightweight request-processing pipeline.
- Modular architecture: Developers can include only the packages required by an application.
- Built-in dependency injection: Services can be registered and injected into application components.
- Unified development model: It supports MVC applications, Razor Pages, Web APIs, Minimal APIs, and Blazor.
- Middleware pipeline: HTTP requests and responses are processed through configurable middleware components.
- Configuration support: Configuration can be loaded from JSON files, environment variables, command-line arguments, and other sources.
- Cloud readiness: It supports containerization, microservices, logging, health checks, and environment-based configuration.
- Side-by-side versioning: Different applications can use different .NET runtime versions on the same computer.
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 →