0% found this document useful (0 votes)
30 views118 pages

.NET Projects and IDE Overview Guide

Uploaded by

Aditi 1235
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views118 pages

.NET Projects and IDE Overview Guide

Uploaded by

Aditi 1235
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

.

NET LAB
FILE
J.C. BOSE UNIVERSITY OF
SCIENCE AND
TECHNOLOGY, YMCA

Submitted To: Ms. Ritika Mam


Submitted By: Mukesh Aggarwal

Class: MCA 3rd Semester


Roll No.:24001602043
List of Projects

[Link]. Exercise Page No. Sign.

1. Understanding IDE and Visual Studio 5-12

2. Introduction to .NET & C# 13-20

3. Introduction to [Link] 21-24


4. To find Sum of Two Numbers (Console) 25
To find Sum of Two Numbers (Form
5. 26
Based)
6. To find Simple Interest (Console) 27
7. To find Simple Interest (Form Based) 28
To find the greater of two numbers
8. 29
(Console)
To find the greater of two numbers (Form
9. 30
Based)
To find the greatest among three numbers
10. 31
(Console)
To find the greatest among three numbers
11. 32
(Form Based)
To Swap Two Numbers Without using
12. 33
Third Variable (Console)
To Swap Two Numbers Without using
13. 34
Third Variable (Form Based)
To Swap Two Numbers using Third
14. 35
Variable (Console)
To Swap Two Numbers using Third
15. 36
Variable (Form Based)
To Implement Simple Calculator (Form
16. 37-40
Based)
To Implement Simple Calculator Using If-
17. Else Ladder (Console Based & Form 41-46
Based)
To Implement Simple Calculator Using
18. 47-49
Switch Case (Console Based)
To Calculate Area of Triangle (Console
19. 50
Based)
To Check whether a number entered is
20. 51
even or odd (Console Based)
To check whether a number entered is
21. 52
+ve, -ve or 0 (Console Based)
To find grade of the student from marks
22. 53
entered (Console Based)
To print multiplication table of a Number
23. 54
(Console Based)
24. To print Fibonacci Series (Console Based) 55
To find Factorial of a number (Console
25. 56
Based)
To convert temperature from Celsius to
26. 57-59
Fahrenheit & vice–versa (Console Based)
To print sum of positive numbers, to exit
27. when a -ve number is entered (Console 60
Based)
To check whether a number lies between
28. 61
1 to 10 using switch case (Console Based)
To check whether a number is palindrome
29. or not using while and do-while loop 62-63
(Console Based)
To find sum of digits of a number using
30. 64-65
while and do-while loop (Console Based)
To print Reverse of a number (Console
31. 66
Based)
To check whether a number is an
32. 67
Armstrong number or not (Console Based)
To print Armstrong numbers lies between
33. 68-71
1 to 1000 using For loop (Console Based)
To demonstrate the use of Nested switch
34. 72-75
case (Console Based)
To demonstrate the use of Operators
35. 76-78
(Unary, Binary, Ternary) (Console Based)
To demonstrate the use of Null-coalescing
36. 79
operator – C# (Console Based)
To demonstrate the use of Null-coalescing
37. 80-81
assignment operator – C# (Console Based)
To demonstrate Simple Class & Object
38. 82-83
(Console Based)
To demonstrate the use of Static Class
39. 84-85
(Console Based)
To demonstrate the use of Abstract Class
40. 86-88
(Console Based)
To demonstrate the use of Sealed Class
41. 89-90
(Console Based)
To demonstrate the use of Partial Class
42. 91-93
(Console Based)
To demonstrate the use of Nested Class
43. 94-96
(Console Based)
To demonstrate the use of Single
44. 97-98
Inheritance (Console Based)
To demonstrate the use of Multilevel
45. 99-101
Inheritance (Console Based)
To demonstrate the use of Hierarchical
46. 102-104
Inheritance (Console Based)
To demonstrate the use of Hybrid
47. 105-108
Inheritance (Console Based)
To demonstrate the use of Multiple
48. Inheritance (using Interfaces) (Console 109-110
Based)
To demonstrate the use of ArrayList
49. 111-112
(Console Based)
To demonstrate the use of Dictionary
50. 113-114
(Console Based)
To demonstrate the use of HashTable
51. 115-116
(Console Based)
To demonstrate the use of List (Console
52. 116-118
Based)
PRACTICAL NO. 1

Understanding IDE and Visual Studio

Integrated Development Environment (IDE):

IDE stands for Integrated Development Environment. It is a software suite that


consolidates the core tools needed for application development—code editor,
compiler/build tools, debugger, and project manager—into a single graphical interface.
By offering syntax highlighting, intelligent code completion (IntelliSense), error
detection, and version-control integration, an IDE streamlines the coding, testing, and
deployment workflows.
The primary goal of an IDE is to maximize developer productivity by streamlining
the entire software development process.

Key Components of IDE:

Component Description
The main area where you write your code. It highlights
Code Editor syntax, checks errors, and may offer suggestions.
Converts human-readable code into machine-executable
Compiler/Interpreter code or runs the code directly (for interpreted languages).
Helps identify and fix bugs by allowing you to pause code
Debugger execution, inspect variables, and step through code line-
by-line.
Automates the process of compiling, linking, and
Build Tools packaging the code into executable files or applications.
Organizes files and folders within a software project. Helps
Project/File Manager developers manage dependencies and modules.
Built-in command-line interface to run scripts, install
Terminal/Console packages, or interact with version control.
Version-Control Allows you to track code changes, commit updates, and
Integration collaborate with others using systems like Git.
Code Completion / Suggests variables, functions, classes, etc., as you type,
IntelliSense speeding up development and reducing errors.
Drag-and-drop interfaces for building GUI applications
UI-Designers (optional) (e.g., in Visual Studio or Android Studio).
Benefits of Using an IDE:

i.) Integration: It combines essential development tools like the code editor,
compiler, and debugger into a single, unified environment, making the
development process more seamless and efficient.
ii.) Time Efficiency: It saves time by automating repetitive tasks such as building,
testing, and debugging, allowing developers to focus more on writing quality
code.
iii.) Learning Support: It helps beginners learn faster by providing tooltips, error
explanations, and direct links to documentation right within the coding
environment.
iv.) Intelligent Assistance: It enhances productivity by offering features like auto-
complete, code suggestions, and refactoring tools that make coding smarter and
faster.
v.) Collaboration Tools: It allows teams to collaborate effectively by integrating
version control systems like Git, enabling code sharing, branching, and merging
without leaving the IDE
vi.) Integrated Testing: It helps in identifying bugs early by supporting unit testing
frameworks and providing built-in tools to run and track test results.

Popular IDE’s:

IDE Name Supported Languages Platform


Visual Studio C#, .NET, C++, [Link] Windows, macOS
JetBrains
.NET, C#, [Link], Xamarin Cross-platform
Rider
Eclipse Java, C/C++, Python, PHP Cross-platform
NetBeans Java, C++, PHP, HTML, CSS Cross-platform
IntelliJ IDEA Java, Kotlin, Groovy, Scala Cross-platform
Xcode Swift, Objective-C macOS only
Code Blocks C, C++ Cross-platform
CLion C, C++, Rust (via plugin) Cross-platform
Geany C, C++, Python, Java, etc. Cross-platform
Difference between IDE and Code Editor:
IDE(Integrated
Aspect Development Code Editor
Environment)
A complete environment for A lightweight tool to write
Definition software development and edit code
Write, compile, debug, and Only to write and edit
Purpose manage code code
No (but can link to one
Includes Compiler? Yes externally)
Debugging Tools Built-in debugger and breakpoints Usually not included
Advanced (IntelliSense, auto- Basic suggestions (can be
Code Suggestions
complete, refactoring) added via plugins)
Project Manages large projects with Minimal or no project
Management folders, configs support
Speed/Performance Heavier, more resource-intensive Lightweight and fast
VS Code, Sublime
Examples Visual Studio, PyCharm, Eclipse
Text, Notepad++
Best for large or complex software Best for quick edits or
Use Case projects small scripts
IDE’s Used for .NET:
Full .NET
IDE Platform Paid/Free
Support
Visual Studio Windows,
Yes Free
(Community) macOS
Visual Studio Windows,
Yes Paid
(Professional/Enterprise) macOS
Windows,
Paid (Free
JetBrains Rider Yes macOS,
for students)
Linux
Windows,
Partial (with
Visual Studio Code extensions)
macOS, Free
Linux
Partial (older macOS, Free (Open
MonoDevelop .NET) Linux source)
Windows,
OmniSharp + Editors Partial (with
macOS, Free
(e.g., Sublime, Vim) setup)
Linux
Key Features of IDE:

Feature Description
Advanced auto-completion and suggestions based on context.
IntelliSense Helps speed up coding and reduces errors.
Integrated Allows you to set breakpoints, watch variables, step through
Debugger code, and diagnose issues efficiently.
Solution Manages all project files, references, and resources in a
Explorer structured tree view.
Project Provides pre-built templates for common project types (e.g.,
Templates Console App, [Link] Web App, Windows Forms).
NuGet Package Lets you easily install, update, and manage third-party libraries
Manager and dependencies.
Full Git support for version control, branching, and committing
Git Integration code— built right into the IDE.
Azure
Directly deploy .NET apps to Microsoft Azure cloud services.
Integration
Unit-Testing Integrated test explorer for writing and running unit tests using
Tools frameworks like MSTest, NUnit, xUnit.
Drag-and-Drop Visual designers for building user interfaces in Windows Forms,
Designer WPF, and MAUI.
Collaborate in real-time with other developers by sharing your
Live Share
IDE session.
Refactoring Easily rename variables, extract methods, and clean up code with
Tools smart suggestions.

Visual Studio
Visual Studio is a powerful Integrated Development Environment (IDE)
developed by Microsoft. It is the official IDE for .NET development, widely used
by developers to build desktop, web, mobile, cloud, and enterprise applications using
languages like C#, [Link], C++, F#, JavaScript, and more.
Visual Studio enables developers to create a wide range of applications, including
desktop, web, mobile, cloud-based, game, and enterprise solutions. It supports
cross-platform development with frameworks like .NET Core, .NET MAUI,
Xamarin, and Blazor.

With built-in tools for code editing, debugging, version control, UI design,
testing, and deployment, Visual Studio provides an end-to-end solution for modern
software development. It also offers integrated Git/Azure DevOps support,
seamless deployment to Microsoft Azure, and a vast extension ecosystem via the
Visual Studio Marketplace.

Visual Studio Interface Overview

The image below shows the Visual Studio IDE, highlighting key areas and tools that
assist in software development:

1. Create a New Project


 Located on the top toolbar (File > New), this option allows you to start a new
solution or application using templates like Console App, [Link], Windows
Forms, etc.
2. Run Your Code
 The green play button (Start Debugging) compiles and executes your application,
launching the output window or console based on the project type.
3. Launch Live Share
 A collaborative tool allowing real-time code editing and debugging with
teammates. No need to share full project files—just a secure Live Share session.
4. Send Feedback
 Helps users report issues or share suggestions directly with Microsoft regarding
the Visual Studio environment.
5. Manage Azure Resources
 Integrates with Microsoft Azure to manage cloud services, databases, and
deployments right from the IDE.
6. Add Controls to Your UI
 Accessed via the Toolbox, this feature allows drag-and-drop placement of UI
components (buttons, textboxes, etc.) when working on Windows Forms or WPF
apps.
7. Manage Files, Projects, and Solutions
 The Solution Explorer shows a tree structure of all files, folders, and references
within a project or solution. You can open, rename, delete, or manage
dependencies here.
8. Collaborate on Code Projects
 Git integration within Solution Explorer enables version control features like
cloning repositories, committing code, branching, merging, and viewing history.

Menu Bar in Visual Studio:

The menu bar in Visual Studio is located at the top of the IDE window and provides
access to all essential commands, tools, and features required for software development.
Each menu item contains a dropdown with multiple options to manage code, projects,
debugging, testing, and more.

Menu Description
Create, open, save, close projects or solutions. Print files and exit the
File IDE.
Offers text editing features like cut, copy, paste, find, replace, and
Edit formatting.
Opens and hides panels like Solution Explorer, Toolbox, Output, Error
View List, etc.
Add new items, references, NuGet packages, or manage project
Project properties.
Build Compile code, build/rebuild solutions, and clean projects.
Set breakpoints, step through code, start/stop debugging, and view
Debug diagnostics.
Test Run unit tests, open Test Explorer, and analyze test results.
Analyze Code analysis, performance profiling, and code metrics tools.
Customize settings, install extensions, and configure development
Tools environment.
Extensions Manage and browse Visual Studio extensions and add-ons.
Window Arrange open windows, reset layouts, and manage multiple views.
Access documentation, release notes, report issues, or get product
Help updates.

Key Components of Visual Studio IDE:


Visual Studio is a full-featured Integrated Development Environment that includes
several important components to support end-to-end software development. Each
component plays a specific role in writing, building, testing, and deploying applications.
Component Description
The main area to write, edit, and navigate source code with
Code Editor syntax highlighting and IntelliSense support.
Displays the hierarchical structure of files, folders, and
Solution Explorer references in your project or solution.
Provides a list of UI controls and components that can be
Toolbox dragged into form or designer views.
Shows the properties of selected controls or files, allowing
Properties Window modification of design-time settings.
Displays build messages, debug output, and status logs during
Output Window execution or compilation.
Shows compilation errors, warnings, and code issues in an
Error List organized list for quick fixes.
Allows connection to databases, servers, services, and cloud
Server Explorer resources like Azure.
Manages version control (Git, Azure DevOps), work items,
Team Explorer and team collaboration tools.
Contains controls to start, stop, and manage debugging
Debug Toolbar sessions, breakpoints, and step commands.
Drag-and-drop interface builder for creating Windows Forms,
Designer View WPF, MAUI, or web UIs.
NuGet Package Manages third-party libraries and packages by installing them
Manager into your projects directly.
Enables real-time collaborative coding sessions with other
Live Share developers.
Organizes, runs, and displays results for unit tests integrated
Test Explorer with MSTest, NUnit, or xUnit.
Extensions Allows installation, update, and management of Visual Studio
Manager extensions and plugins.

Editions of Visual Studio:


Microsoft offers Visual Studio in different editions to cater to various needs—ranging
from individual learners to enterprise-level teams.
Edition Target Key Features Limitations /
Audience Extras
Community Students, IntelliSense, debugging, unit Not for enterprises
(Free) hobbyists, open- testing, multi-language support, with > 5
source Git/GitHub integration, developers (except
contributors, Marketplace extensions, app academic or open-
small teams (≤ 5 development for Windows, source)
users) web, mobile, cloud
Professional Professional All Community features + Optional MSDN
(Paid) developers, IntelliTrace, CodeLens, Azure subscription with
small-to-mid DevOps integration, advanced Azure credits,
teams diagnostics/profiling software, and
training
Enterprise Large All Professional features + Designed for
(Paid – enterprises, Snapshot Debugging, Live Unit mission-critical,
Premium) advanced Testing, architecture validation, large-scale
developers, load testing, IntelliTrace projects
DevOps teams history, priority Microsoft
support

Why Visual Studio is Ideal for .NET Development?


Visual Studio is specifically designed to work seamlessly with the .NET ecosystem,
which includes:
 .NET Framework
 .NET Core
 .NET 5, 6, 7, and 8
 [Link] (Web apps and APIs)
 WinForms and WPF (Desktop apps)
 Blazor (Single Page Web Apps)
 .NET MAUI and Xamarin (Cross-platform mobile apps)

It provides everything you need to build, test, debug, and deploy .NET applications—
all in one place.
Visual Studio is the most powerful and comprehensive IDE for developing .NET
applications. It supports a wide range of project types, integrates smart tools to assist
development, and offers strong debugging, testing, and deployment features—making
it the go-to environment for C# and .NET developers.
PRACTICAL NO. 2

Introduction to .NET & C#


 .NET:
.NET is a free, open-source, and cross-platform software development platform created
by Microsoft. It provides a runtime environment and a set of libraries, languages, and
tools for building various types of applications, such as:
 Web applications
 Desktop applications
 Mobile apps
 Cloud services
 APIs
 Games
 IoT applications
The modern version is called .NET (Core) or just .NET, replacing the older .NET
Framework.

Key Components of .NET:

S. No Component Description
Common Core execution engine that manages
1. Language memory, type safety, garbage collection,
Runtime (CLR) and code execution.
Provides core functionality like file I/O,
2. Base Class Library (BCL) collections, threading, and system
utilities.
Common Type Ensures consistent data types across all
3.
System (CTS) .NET languages.
Intermediate Language Intermediate code generated by
4.
(IL) compilers; executed by the CLR via JIT.
Just-In-Time Converts IL into native machine code at
5.
Compiler (JIT) runtime.
Compiled output (.dll/.exe) with IL code
6. Assemblies and metadata; fundamental deployment
unit.
.NET Languages (C#, F#, Programming languages that are
7.
etc.) compiled to IL and run on the CLR.
Framework for building fast and scalable
8. [Link] Core
web apps and APIs.
Entity Framework Core ORM for database access using LINQ
9.
(EF Core) and C# objects.
Official IDEs for writing, debugging, and
10. Visual Studio / VS Code
deploying .NET apps.

Advantages of .NET:

 Cross-platform (Windows, macOS, Linux)


 Multiple language support
 Rich libraries and APIs
 Strong security model
 High performance with JIT and AOT compilation
 Support for cloud (Azure) and microservices
 Tooling support (Visual Studio, VS Code)

.NET Technology Timeline:

Release
Version Purpose / Features / Evolution
Year
.NET FRAMEWORK
Initial release with CLR, BCL, Windows Forms,
1.0 2002
[Link] Web Forms. Supported only Windows.
Security improvements, support for mobile controls
1.1 2003
([Link] Mobile).
Major update with Generics, anonymous methods,
2.0 2005
partial classes. Introduced SQL Server integration.
Introduced WPF (UI), WCF (communication), WF
3.0 2006 (workflow), and CardSpace. Enhanced application
architecture.
Added LINQ, extension methods, lambda
3.5 2007 expressions. Improved [Link] with AJAX
support.
Introduced parallel computing (TPL), MEF
4.0 2010 (extensibility), improved CLR and garbage
collection.
Support for async/await, WebSockets, and improved
4.5 2012
HTTP pipeline in [Link].
Performance and debugging improvements. Support
4.5.1 / 4.5.2 2013–2014
for highDPI displays.
4.6 / 4.6.1 / Introduced RyuJIT for 64-bit, HTTP/2, and
2015–2016
4.6.2 cryptographic enhancements.
4.7 / 4.7.1 / Added .NET Standard 2.0 support, accessibility
2017–2018
4.7.2 improvements, and high DPI support.
Last version of .NET Framework. Improved JIT,
4.8 2019
Windows Forms DPI, accessibility. Legacy-only.

.NET CORE
Lightweight, modular, cross-platform runtime.
1.0 2016
Command-line tools introduced.
1.1 2016 Minor update for compatibility and stability.
Added support for .NET Standard 2.0, broader API
2.0 2017
coverage, and runtime stability.
First LTS release. Introduced SignalR Core,
2.1 (LTS) 2018
HttpClientFactory, performance optimizations.
Introduced Windows desktop support (WPF,
3.0 2019 WinForms), C# 8, Blazor (WebAssembly), gRPC
support.
Stabilized 3.0 features. Long-term support. Became
3.1 (LTS) 2019
the most widely adopted version at the time.
.NET
Unified .NET Core and Framework. Removed
.NET 5 2020 “Core” name. New single SDK, better performance,
C# 9, cloud-ready.
First LTS unified version. Introduced .NET MAUI
.NET 6
2021 preview, minimal APIs, Hot Reload, and Blazor
(LTS) Desktop.
.NET 7 Focused on performance, Native AOT, cloud-native
2022
(STS) improvements. Support ended mid-2024.
Production-ready .NET MAUI, Blazor
.NET 8
2023 enhancements, AI/ML improvements, and faster
(LTS) runtimes.
.NET 9 Improved cloud support, code-first APIs, enhanced
2024
(STS) Hot Reload and compiler speed.
.NET 10 Anticipated: deeper AI integration, enhanced native
(LTS) – Nov 2025 support, real-time analytics features (not officially
expected released yet).

Since .NET 5, Microsoft moved towards a single unified platform. Now everything is
under the umbrella of .NET (6, 7, 8, etc.), with updates and improvements released
regularly.

 C#:
C# (pronounced "C-Sharp") is a powerful, modern, object-oriented programming
language developed by Microsoft in the early 2000s. It was introduced as part of the
company's .NET initiative to provide a language that was robust, easy to use, flexible,
and suitable for building a wide range of applications from desktop software to web
applications and cloud services.

C# is deeply integrated into the .NET ecosystem and is the most widely used language
for developing .NET applications. It draws inspiration from several programming
languages, including C, C++, and Java, offering a blend of performance, simplicity, and
developer productivity.

Features / Characteristics of C#:

i.) Object-Oriented – Supports all four pillars of OOP for structured and reusable
code.
ii.) Type-Safe – Prevents type errors by enforcing strict type rules at compile time.
iii.) Automatic Memory Management – Uses Garbage Collection to manage memory
automatically.
iv.) Rich Standard Library – Offers a vast collection of built-in classes and functions.
v.) Component-Oriented – Encourages modular design through reusable assemblies
and DLLs.
vi.) Interoperable – Can integrate with Windows APIs, COM, and other .NET
languages.
vii.) Asynchronous Programming – Enables responsive apps with async and await
support.
viii.) LINQ Support – Allows SQL-like queries on in-memory objects and data
sources.
ix.) Exception Handling – Provides structured error management using try-catch-
finally blocks.
x.) Cross-Platform – Runs on Windows, Linux, and macOS using .NET Core/.NET
5+.
xi.) Modern Language Features – Continuously updated with features like pattern
matching, records, and lambdas.
xii.) Powerful IDE Support – Seamlessly works with Visual Studio and Visual Studio
Code for efficient development.

History and Origin:


 C# was developed by Microsoft and led by Anders Hejlsberg, a prominent software
engineer who also created Turbo Pascal and was the chief architect of Delphi.
 The language was officially released in 2000 alongside the first version of the .NET
Framework.
 The primary motivation behind C# was to create a simple, modern, and object-
oriented language that could operate effectively in Microsoft’s evolving software
development landscape.
 It was standardized by ECMA (ECMA-334) and ISO, which means its specification
is open and can be implemented by others.

Application of C#:

Application
Description
Type
Desktop C# is widely used with Windows Forms, WPF, and .NET MAUI
Applications to build powerful Windows GUI apps.
Web Using [Link] Core, developers build scalable and high-
Applications performance websites, web APIs, and portals.
Mobile With Xamarin and .NET MAUI, C# can be used to develop cross-
Applications platform mobile apps for Android & iOS.
Cloud C# integrates well with Microsoft Azure for creating scalable and
Applications reliable cloud-based services.
Game Unity, a popular game engine, uses C# as its primary scripting
Development language for 2D and 3D games.
Enterprise C# is used for building large-scale enterprise software like ERPs,
Applications CRMs, and accounting systems.
IoT With .NET IoT libraries, developers can write C# code for sensors,
Applications devices, and Raspberry Pi.
Machine
[Link] allows C# developers to add machine learning features
Learning
to .NET applications.
Apps
Automation C# is used for writing scripts and tools to automate tasks on
Tools Windows platforms.
Database C# with [Link] or Entity Framework is ideal for building
Applications applications that interact with databases.
Web Services Build RESTful and SOAP-based web services using [Link]
& APIs Core Web API.
Cross-Platform Using .NET Core/.NET 5+, developers can build apps that run on
Apps Windows, Linux, and macOS.

C# Data Types:
In C#, data types specify the kind of values that variables can hold. Being a strongly
typed language, C# enforces type safety, ensuring fewer runtime errors and better
memory management.

C# data types are broadly divided into the following categories:

1. Value Types

Value types store actual data directly in memory (stack). Assigning one variable to
another copies the value.

 Integral Types
 byte → 8-bit unsigned integer (0 to 255)
 sbyte → 8-bit signed integer (-128 to 127)
 short → 16-bit signed integer
 ushort → 16-bit unsigned integer
 int → 32-bit signed integer (commonly used)
 uint → 32-bit unsigned integer
 long → 64-bit signed integer
 ulong → 64-bit unsigned integer
 Floating-Point Types

 float → 32-bit single precision


 double → 64-bit double precision (more accurate)
 decimal → 128-bit high precision, often used for financial calculations

 Other Value Types


 char → Represents a single 16-bit Unicode character
 bool → Represents Boolean values (true or false)
 enum → User-defined set of named constants
 struct → User-defined value type that can include variables, methods, and
constructors

2. Reference Types

Reference types store the memory address of data (heap). Multiple variables can
reference the same object.

 string → A sequence of characters (immutable)


 object → Base type of all other types in C#
 class → User-defined reference types containing fields, properties, and methods
 array → Collection of elements of the same type stored in sequence
 delegate → Reference to a method, commonly used in event handling

3. Nullable Types

Value types can be made nullable using ?, allowing them to represent an undefined
value.

int? age = null;

4. Dynamic Type

Introduced in C# 4.0, allows variables to store any type, with type checking deferred
until runtime.

dynamic value = 10;

value = "Now I am a string";

5. Implicitly Typed Variables

Declared using the var keyword. The compiler infers the type at compile time.

var num = 10; // inferred as int

var name = "Mukesh"; // inferred as string


Advantages of Using C#:

i.) Easy to learn for beginners with a clear syntax


ii.) Highly readable and maintainable code
iii.) Supported by a large community and backed by Microsoft
iv.) Scalable for small to large enterprise applications
v.) Wide ecosystem of libraries, tools, and frameworks

C# Language Overview

C# is the primary programming language developed by Microsoft for the .NET platform.
It is a modern, object-oriented language that supports key features such as strong type
safety, automatic memory management, LINQ (Language Integrated Query), and
asynchronous programming.

C# is designed for building secure, scalable, and high-performance applications


across various domains—ranging from desktop and web applications to cloud services
and mobile apps. It offers the power of low-level control similar to C++, combined with
the simplicity and productivity of modern languages.

Thanks to seamless integration with the .NET SDK and tools like Visual Studio, C#
provides excellent development support for cross-platform solutions. Its versatility makes
it a preferred choice for developing enterprise-level systems, RESTful APIs, games (via
Unity), and cloud-native applications.
PRACTICAL NO. 3

Introduction to [Link]

Introduction to [Link]:
Visual Basic .NET ([Link]) is a high-level, object-oriented programming language
developed by Microsoft as part of the .NET Framework. It is the successor to the classic
Visual Basic (VB6) language, redesigned to work with the modern .NET platform.
[Link] combines the simplicity of Visual Basic syntax with the power of the .NET
libraries, making it suitable for building desktop, web, cloud, and database
applications. Unlike its predecessor, [Link] is fully object-oriented, strongly typed,
and interoperable with other .NET languages such as C# and F#.

Key Features of [Link]:


 Object-Oriented – Supports encapsulation, inheritance, and polymorphism.
 Multi-Paradigm – Enables procedural, event-driven, and object-oriented
programming.
 Cross-Platform – With .NET 5 and later, [Link] applications can run on
Windows, Linux, and macOS.
 Type Safety – Strongly typed language that reduces runtime errors.
 Automatic Memory Management – Uses garbage collection to reclaim unused
memory.
 Exception Handling – Provides Try…Catch…Finally blocks for robust error
handling.
 Rich Class Library – Full access to the Base Class Library (BCL) for I/O, data
access, networking, etc.
 Integration – Works seamlessly with Windows APIs, COM components, and cloud
services like Azure.
 Rapid GUI Development – Visual Studio offers drag-and-drop design tools for
Windows Forms and WPF.
 Interoperability – Can directly use code and libraries from other .NET languages.

History and Evolution of [Link]


 1991 – VB 1.0: First version, made Windows GUI programming simple.
 1998 – VB 6.0: Last classic Visual Basic version.
 2002 – [Link] 1.0: Rewritten for the .NET Framework, became fully object-
oriented.
 2005 – [Link] 2005: Introduced Generics, Partial Classes.
 2010 onwards: Added modern features like LINQ and Async/Await.
 2020+: Runs on modern .NET (5, 6, 7, 8), with cross-platform support.

[Link] Data Types:


Like other .NET languages, [Link] data types are divided into Value Types and
Reference Types.
 Value Types (store actual data, stack memory)
▪ Numeric: Byte, SByte, Short, UShort, Integer, UInteger, Long, ULong, Decimal,
Single, Double
▪ Logical: Boolean
▪ Character: Char
▪ Date/Time: Date
▪ User-defined: Enum, Structure
 Reference Types (store address of data, heap memory)
▪ String – Sequence of characters
▪ Object – Base type of all data types
▪ Class – Blueprint for creating objects
▪ Array – Collection of elements of same type
▪ Delegate – References a method, used in event handling
 Nullable Types – Allow value types to hold Nothing (similar to null in C#).
 Dynamic Types – The Object type can hold any data, resolved at runtime.

[Link] Program Structure


A simple [Link] program is made up of modules, classes, and procedures. The
execution begins at the Sub Main() method.
Imports System

Module HelloWorld
Sub Main ()
[Link]("Hello, [Link]!")
Console. ReadLine()
End Sub
End Module

Explanation:
 Imports System → Imports namespaces for built-in functionality.
 Module → Defines a container for methods and variables.
 Sub Main () → Entry point of the program. Execution starts here.
 [Link]() → Prints output on the console.
 End Statements → End Sub marks the end of a procedure. End Module marks the
end of a module.

Comparison: [Link] vs C#
Both [Link] and C# are modern programming languages developed by Microsoft
under the .NET Framework. They are very similar in functionality (since both
compile to the same MSIL and run on the Common Language Runtime (CLR)),
but they differ in syntax, readability, and popularity.

Aspect [Link] C#
Case Sensitivity Not case-sensitive (Dim A = Case-sensitive (int A ≠ int a)
Dim a)
Syntax Style English-like, verbose Compact, C/Java-style

Popularity Still used in legacy & Widely used in industry, Unity,


education cloud
Keywords Uses End If, End Sub, etc. Uses { } braces and ;
semicolons
Community Smaller but stable Large and very active
Support

Applications of [Link]:
[Link] is a versatile programming language developed by Microsoft as part of the
.NET Framework. It is widely used for creating Windows-based applications, web
applications, and enterprise-level solutions.
 Desktop Applications – Windows Forms, WPF applications.
 Web Applications – [Link] web apps and portals.
 Database Applications – Using [Link] and Entity Framework.
 Enterprise Systems – ERP, CRM, and financial software.
 Automation Tools – Scripts for automating Windows tasks.
 Legacy System Maintenance – Updating old VB-based projects into modern .NET
solutions.

Advantages of [Link]:
 Easy-to-learn syntax, beginner-friendly.
 Strongly typed and object-oriented.
 Integrated with .NET libraries and Visual Studio.
 Cross-platform support with modern .NET versions.
 Suitable for rapid application development.
 Interoperable with other .NET languages.

Conclusion

[Link] remains an important programming language within the .NET ecosystem.


Although C# has overtaken it in popularity, [Link] is still relevant for educational
purposes, maintaining legacy systems, and developing small to medium-scale
Windows applications. Its English-like syntax, integration with Visual Studio, and
powerful .NET libraries make it an excellent language for beginners to learn
programming concepts and application development.
PRACTICAL NO. 4
Program: To find Sum of Two Numbers (Console)
 CODE:
C# [Link]
// C# Program to add two numbers ' [Link] Program to add two numbers
(Console) (Console)
using System; Imports System
public class Test Module Module1
{ Sub Main()
public static void Main() Dim a, b, sum As Integer
{
[Link]("Enter the first
int a, b, sum; number: ")
[Link]("Enter the first a=
number: "); Convert.ToInt32([Link]())
a=
Convert.ToInt32([Link]()); [Link]("Enter the second
number: ")
[Link]("Enter the second b=
number: "); Convert.ToInt32([Link]())
b=
Convert.ToInt32([Link]()); sum = a + b ' addition
sum = a + b; // addition [Link]("Sum of two
numbers is: " & sum)
[Link]("Sum of two
numbers is: " + sum); End Sub
} End Module
}
 OUTPUT:  OUTPUT:
PRACTICAL NO. 5
Program: To find Sum of Two Numbers (Form Based)

 CODE:
C# [Link]
// C# Windows Form Application: Sum ' [Link] Windows Form Application:
of two numbers Sum of two numbers
namespace WinFormsApp1 Public Class Form1
{public partial class Form1 : Form{ Private Sub Button1_Click(sender As
Object, e As EventArgs) Handles
public Form1(){
[Link]
InitializeComponent();}
Dim A As Integer
private void Form1_Load(object
Dim B As Integer
sender, EventArgs e){
Dim Sum As Integer
}
private void button1_Click(object A = Val([Link])
sender, EventArgs e)
B = Val([Link])
{ int A, B, Sum;
Sum = A + B
A=
Convert.ToInt32([Link]); [Link]("The Sum of " &
A & " and " & B & " is : " & Sum,
B= "RESULT")
Convert.ToInt32([Link]);
End Sub
Sum = A + B;
Private Sub Button2_Click(sender As
[Link]("The Sum of " + Object, e As EventArgs) Handles
A + " and " + B + " is : " + Sum, [Link]
"RESULT");}
[Link]()
private void button2_Click(object
End Sub
sender, EventArgs e)
End Class
{ [Link]();
}}}
 OUTPUT:
 OUTPUT:
PRACTICAL NO. 6
Program: To find Simple Interest (Console)
 CODE:
C# [Link]
// C# Program to calculate Simple ' [Link] Program to calculate Simple
Interest Interest
using System; Imports System
class Program Module Module1
{ Sub Main()
static void Main() Dim P, R, T, SI As Double
{
double P, R, T, SI; [Link]("Enter Principal
[Link]("Enter Principal Amount: ")
Amount: "); P=
P= [Link]([Link]())
[Link]([Link]());
[Link]("Enter Rate of Interest: [Link]("Enter Rate of Interest:
"); ")
R= R=
[Link]([Link]()); [Link]([Link]())

[Link]("Enter Time (in years): [Link]("Enter Time (in years):


"); ")
T= T=
[Link]([Link]()); [Link]([Link]())

// Formula: SI = (P * R * T) / 100 ' Formula: SI = (P * R * T) / 100


SI = (P * R * T) / 100; SI = (P * R * T) / 100

[Link]("Simple Interest = [Link]("Simple Interest =


" + SI); " & SI)
} End Sub
} End Module

 OUTPUT:  OUTPUT:
PRACTICAL NO. 7
Program: To find Simple Interest (Form Based)

 CODE:
' [Link] Program to calculate Simple Interest
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles [Link]
Dim P, R, T, SI As Double

P = [Link]([Link])
R = [Link]([Link])
T = [Link]([Link])

SI = (P * R * T) / 100

[Link]("Simple Interest = " & SI, "RESULT")


End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles [Link]


[Link]()
End Sub
End Class

 OUTPUT:
PRACTICAL NO. 8
Program: To find the greater of two numbers (Console)
 CODE:
C# [Link]
// C# Program to find the greater of two ' [Link] Program to find the greater of
numbers two numbers
using System; Imports System
class Program
{ Module Module1
static void Main() Sub Main()
{ Dim a, b As Integer
int a, b;
[Link]("Enter first number: ")
[Link]("Enter first number: "); a=
a= Convert.ToInt32([Link]())
Convert.ToInt32([Link]());
[Link]("Enter second number:
[Link]("Enter second number: ")
"); b=
b= Convert.ToInt32([Link]())
Convert.ToInt32([Link]());
If a > b Then
if (a > b) [Link]("Greatest
[Link]("Greatest number is: " & a)
number is: " + a); ElseIf b > a Then
else if (b > a) [Link]("Greatest
[Link]("Greatest number is: " & b)
number is: " + b); Else
else [Link]("Both numbers
[Link]("Both numbers are equal")
are equal"); End If
} End Sub
} End Module

 OUTPUT:  OUTPUT:
PRACTICAL NO. 9
Program: To find the greater of two numbers (Form Based)
 CODE:
C# [Link]
// C# Windows Form Application: ' [Link] Windows Form Application:
Greater of two numbers Greater of two numbers
namespace Greater_of_Two_Form1{ Public Class Form1
public partial class Form1 : Form{ Private Sub Button1_Click(sender As
public Form1() Object, e As EventArgs) Handles
{ [Link]
InitializeComponent();} Dim a, b As Integer
private void button1_Click(object
a = Convert.ToInt32([Link])
sender, EventArgs e){
b = Convert.ToInt32([Link])
int a =
Convert.ToInt32([Link]); If a > b Then
int b = [Link]("Greatest
Convert.ToInt32([Link]); number is: " & a, "RESULT")
if (a > b) ElseIf b > a Then
[Link]("Greatest [Link]("Greatest
number is : " + a, "RESULT"); number is: " & b, "RESULT")
else if (b > a) Else
[Link]("Greatest [Link]("Both numbers
number is : " + b, "RESULT"); are equal", "RESULT")
else End If
[Link]("Both End Sub
numbers are equal", "RESULT");
} Private Sub Button2_Click(sender As
private void button2_Click(object Object, e As EventArgs) Handles
sender, EventArgs e) [Link]
{ [Link]()
[Link](); End Sub
}}} End Class

 OUTPUT:  OUTPUT:
PRACTICAL NO. 10
Program: To find the greatest among three numbers (Console)
 CODE:
C# [Link]
// C# Program to find greatest among ' [Link] Program to find greatest
three numbers among three numbers
using System; Imports System
class Program Module Module1
{ Sub Main()
static void Main() Dim a, b, c As Integer
{ [Link]("Enter first number: ")
int a, b, c; a=
[Link]("Enter first number: "); Convert.ToInt32([Link]())
a=
[Link]("Enter second number:
Convert.ToInt32([Link]());
")
[Link]("Enter second number: b=
"); Convert.ToInt32([Link]())
b=
[Link]("Enter third number: ")
Convert.ToInt32([Link]());
c=
[Link]("Enter third number: "); Convert.ToInt32([Link]())
c=
If a > b And a > c Then
Convert.ToInt32([Link]());
[Link]("Greatest
if (a > b && a > c) number is: " & a)
[Link]("Greatest ElseIf b > a And b > c Then
number is: " + a); [Link]("Greatest
else if (b > a && b > c) number is: " & b)
[Link]("Greatest ElseIf c > a And c > b Then
number is: " + b); [Link]("Greatest
else if (c > a && c > b) number is: " & c)
[Link]("Greatest Else
number is: " + c); [Link]("Some numbers
else are equal")
[Link]("Some numbers End If
are equal"); End Sub
} End Module
}
 OUTPUT:  OUTPUT:
PRACTICAL NO. 11
Program: To find the greatest among three numbers (Form Based)
 CODE:
' [Link] Windows Form Application: Greatest of three numbers
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles [Link]
Dim a, b, c As Integer
a = Convert.ToInt32([Link])
b = Convert.ToInt32([Link])
c = Convert.ToInt32([Link])
If a > b AndAlso a > c Then
[Link]("Greatest number is: " & a, "RESULT")
ElseIf b > a AndAlso b > c Then
[Link]("Greatest number is: " & b, "RESULT")
ElseIf c > a AndAlso c > b Then
[Link]("Greatest number is: " & c, "RESULT")
Else
[Link]("Some numbers are equal", "RESULT")
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles
[Link]
[Link]()
End Sub
End Class

 OUTPUT:
PRACTICAL NO. 12
Program: To Swap Two Numbers Without using Third Variable (Console)
 CODE:
C# [Link]
// C# Program to swap two numbers ' [Link] Program to swap two numbers
without third variable without third variable
using System; Imports System

class Program Module Module1


{ Sub Main()
static void Main() Dim a, b As Integer
{
int a, b; [Link]("Enter first number: ")
a=
[Link]("Enter first number: "); Convert.ToInt32([Link]())
a=
Convert.ToInt32([Link]()); [Link]("Enter second number:
")
[Link]("Enter second number: b=
"); Convert.ToInt32([Link]())
b=
Convert.ToInt32([Link]()); [Link]("Before Swap: a =
" & a & ", b = " & b)
[Link]("Before Swap: a =
" + a + ", b = " + b); ' Swapping logic
a=a+b
// Swapping logic b=a-b
a = a + b; a=a-b
b = a - b;
a = a - b; [Link]("After Swap: a = "
& a & ", b = " & b)
[Link]("After Swap: a = " End Sub
+ a + ", b = " + b); End Module
}
}

 OUTPUT:  OUTPUT:
PRACTICAL NO. 13
Program: To Swap Two Numbers Without using Third Variable (Form Based)
 CODE:
' [Link] Windows Form Application: Swap two numbers without third variable
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles [Link]
Dim a, b As Integer

a = Convert.ToInt32([Link])
b = Convert.ToInt32([Link])

' Swapping without third variable


a=a+b
b=a-b
a=a-b

[Link]("After Swap: a = " & a & ", b = " & b, "RESULT")

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles [Link]


[Link]()
End Sub

End Class

 OUTPUT:
PRACTICAL NO. 14
Program: To Swap Two Numbers using Third Variable (Console)
 CODE:
C# [Link]
// C# Program to swap two numbers ' [Link] Program to swap two numbers
without third variable without third variable
using System; Imports System

class Program Module Module1


{ Sub Main()
static void Main() Dim a, b As Integer
{
int a, b; [Link]("Enter first number: ")
a=
[Link]("Enter first number: "); Convert.ToInt32([Link]())
a=
Convert.ToInt32([Link]()); [Link]("Enter second number:
")
[Link]("Enter second number: b=
"); Convert.ToInt32([Link]())
b=
Convert.ToInt32([Link]()); [Link]("Before Swap: a =
" & a & ", b = " & b)
[Link]("Before Swap: a =
" + a + ", b = " + b); ' Swapping logic
a=a+b
// Swapping logic b=a-b
a = a + b; a=a-b
b = a - b;
a = a - b; [Link]("After Swap: a = "
& a & ", b = " & b)
[Link]("After Swap: a = " End Sub
+ a + ", b = " + b); End Module
}
}

 OUTPUT:  OUTPUT:
PRACTICAL NO. 15
Program: To Swap Two Numbers using Third Variable (Form Based)
 CODE:
' [Link] Windows Form Application: Swap two numbers using third variable

Public Class Form1


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles [Link]
Dim a, b, temp As Integer
a = Convert.ToInt32([Link])
b = Convert.ToInt32([Link])

' Swapping with third variable


temp = a
a=b
b = temp

[Link]("After Swap: a = " & a & ", b = " & b, "RESULT")


End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles [Link]


[Link]()
End Sub
End Class

 OUTPUT:
PRACTICAL NO. 16
Program: To Implement Simple Calculator (Form Based)
 CODE:
// C# Windows Form Application: Simple Calculator
using System;
using [Link];
namespace Calculator1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
double a = [Link]([Link]);
double b = [Link]([Link]);
[Link]("Sum = " + (a + b), "RESULT");
}
private void button2_Click(object sender, EventArgs e)
{
double a = [Link]([Link]);
double b = [Link]([Link]);
[Link]("Difference = " + (a - b), "RESULT");
}
private void button3_Click(object sender, EventArgs e)
{
double a = [Link]([Link]);
double b = [Link]([Link]);
[Link]("Product = " + (a * b), "RESULT");
}
private void button4_Click(object sender, EventArgs e)
{
double a = [Link]([Link]);
double b = [Link]([Link]);

if (b != 0)
[Link]("Quotient = " + (a / b), "RESULT");
else
[Link]("Division by zero not allowed", "ERROR");
}
private void button5_Click(object sender, EventArgs e)
{
[Link]();
}
}
}

 OUTPUT:
 CODE:
' [Link] Windows Form Application: Simple Calculator
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
[Link]
Dim a, b As Double
a = [Link]([Link])
b = [Link]([Link])
[Link]("Sum = " & (a + b), "RESULT")
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles


[Link]
Dim a, b As Double
a = [Link]([Link])
b = [Link]([Link])
[Link]("Difference = " & (a - b), "RESULT")
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles


[Link]
Dim a, b As Double
a = [Link]([Link])
b = [Link]([Link])
[Link]("Product = " & (a * b), "RESULT")
End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles


[Link]
Dim a, b As Double
a = [Link]([Link])
b = [Link]([Link])
If b <> 0 Then
[Link]("Quotient = " & (a / b), "RESULT")
Else
[Link]("Division by zero not allowed", "ERROR")
End If
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles
[Link]
[Link]()
End Sub
End Class

 OUTPUT:
PRACTICAL NO. 17
Program: To Implement Simple Calculator Using If-Else Ladder (Console
Based & Form Based)
 CODE:
// C# Console Program: Calculator using if-else ladder
using System;

class Program
{
static void Main()
{
double a, b, result = 0;
char op;

[Link]("Enter first number: ");


a = [Link]([Link]());

[Link]("Enter second number: ");


b = [Link]([Link]());

[Link]("Enter an operator (+, -, *, /): ");


op = [Link]([Link]());

if (op == '+')
result = a + b;
else if (op == '-')
result = a - b;
else if (op == '*')
result = a * b;
else if (op == '/')
{
if (b != 0)
result = a / b;
else
[Link]("Division by zero not allowed!");
}
else
[Link]("Invalid Operator!");

[Link]("Result = " + result);


}
}
 OUTPUT:

 CODE:
' [Link] Console Program: Calculator using if-else ladder
Imports System
Module Module1
Sub Main()
Dim a, b, result As Double
Dim op As Char

[Link]("Enter first number: ")


a = [Link]([Link]())

[Link]("Enter an operator (+, -, *, /): ")


op = [Link]([Link]())

[Link]("Enter second number: ")


b = [Link]([Link]())

If op = "+"c Then
result = a + b
ElseIf op = "-"c Then
result = a - b
ElseIf op = "*"c Then
result = a * b
ElseIf op = "/"c Then
If b <> 0 Then
result = a / b
Else
[Link]("Division by zero not allowed!")
End If
Else
[Link]("Invalid Operator!")
End If

[Link]("Result = " & result)


End Sub
End Module

 OUTPUT:

 CODE:
// C# Windows Form Application: Calculator using If-Else Ladder
namespace Calculator_If_Else_Form1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
double a, b, result = 0;
string op;

a = [Link]([Link]);
b = [Link]([Link]);
op = [Link]; // Operator from ComboBox

if (op == "+")
result = a + b;
else if (op == "-")
result = a - b;
else if (op == "*")
result = a * b;
else if (op == "/")
{
if (b != 0)
result = a / b;
else
[Link]("Division by zero not allowed!", "ERROR");
}
else
[Link]("Invalid Operator!", "ERROR");

[Link]("Result = " + result, "RESULT");


}

private void button2_Click(object sender, EventArgs e)


{
[Link]();
}
}
}

 OUTPUT:
 CODE:
' [Link] Windows Form Application: Calculator using If-Else Ladder
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
[Link]
Dim a, b, result As Double
Dim op As String
a = [Link]([Link])
b = [Link]([Link])
op = [Link] ' Operator from ComboBox

If op = "+" Then
result = a + b
ElseIf op = "-" Then
result = a - b
ElseIf op = "*" Then
result = a * b
ElseIf op = "/" Then
If b <> 0 Then
result = a / b
Else
[Link]("Division by zero not allowed!", "ERROR")
End If
Else
[Link]("Invalid Operator!", "ERROR")
End If

[Link]("Result = " & result, "RESULT")


End Sub

Public Sub New()


InitializeComponent()
' Add operators to ComboBox
[Link]("+")
[Link]("-")
[Link]("*")
[Link]("/")
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles [Link]
[Link]()
End Sub
End Class
 OUTPUT:
PRACTICAL NO. 18
Program: To Implement Simple Calculator Using Switch Case (Console
Based)
 CODE:
// C# Console Program: Calculator using switch case
using System;

class Program
{
static void Main()
{
double a, b;
char op;

[Link]("Enter first number: ");


a = [Link]([Link]());

[Link]("Enter an operator (+, -, *, /): ");


op = [Link]([Link]());

[Link]("Enter second number: ");


b = [Link]([Link]());

switch (op)
{
case '+':
[Link]("Result = " + (a + b));
break;
case '-':
[Link]("Result = " + (a - b));
break;
case '*':
[Link]("Result = " + (a * b));
break;
case '/':
if (b != 0)
[Link]("Result = " + (a / b));
else
[Link]("Division by zero not allowed!");
break;
default:
[Link]("Invalid Operator!");
break;
}
}
}

 OUTPUT:

 CODE:
' [Link] Console Program: Calculator using Select Case
Imports System

Module Module1
Sub Main()
Dim a, b As Double
Dim op As Char

[Link]("Enter first number: ")


a = [Link]([Link]())

[Link]("Enter an operator (+, -, *, /): ")


op = [Link]([Link]())

[Link]("Enter second number: ")


b = [Link]([Link]())

Select Case op
Case "+"c
[Link]("Result = " & (a + b))
Case "-"c
[Link]("Result = " & (a - b))
Case "*"c
[Link]("Result = " & (a * b))
Case "/"c
If b <> 0 Then
[Link]("Result = " & (a / b))
Else
[Link]("Division by zero not allowed!")
End If
Case Else
[Link]("Invalid Operator!")
End Select
End Sub
End Module

 OUTPUT:
PRACTICAL NO. 19
Program: To Calculate Area of Triangle (Console Based)
 CODE:
C# [Link]
// C# Console Program: Calculate Area ' [Link] Console Program: Calculate
of Triangle Area of Triangle
using System; Imports System
class Program
Module Module1
{ Sub Main()
static void Main() Dim baseLength, height, area As
Double
{
double baseLength, height, area; [Link]("Enter the base of the
triangle: ")
[Link]("Enter the base of the baseLength =
triangle: "); [Link]([Link]())
baseLength =
[Link]([Link]()); [Link]("Enter the height of the
triangle: ")
[Link]("Enter the height of the
height =
triangle: ");
[Link]([Link]())
height =
[Link]([Link]()); area = 1/2 * baseLength * height
area = (double)1/2 * baseLength *
height; [Link]("The area of the
triangle is: " & area)
[Link]("The area of the
End Sub
triangle is: " + area);
End Module
}
}

 OUTPUT:  OUTPUT:
PRACTICAL NO. 20
Program: To Check whether a number entered is even or odd (Console Based)
 CODE:
C# [Link]
// C# Console Program: Check Even or ' [Link] Console Program: Check Even
Odd or Odd
using System; Imports System

class Program
Module Module1
{ Sub Main()
static void Main() Dim num As Integer

{ [Link]("Enter a number: ")


int num; num =
Convert.ToInt32([Link]())
[Link]("Enter a number: ");
num = If num Mod 2 = 0 Then
Convert.ToInt32([Link]()); [Link](num & " is
Even")
if (num % 2 == 0) Else
[Link](num & " is
[Link](num + " is
Odd")
Even");
End If
else End Sub
[Link](num + " is End Module
Odd");
}
}

 OUTPUT:  OUTPUT:
PRACTICAL NO. 21
Program: To check whether a number entered is +ve, -ve or 0 (Console Based)
 CODE:
C# [Link]
// C# Console Program: Check Positive, ' [Link] Console Program: Check
Negative, or Zero Positive, Negative, or Zero
using System; Imports System
class Program Module Module1
{
Sub Main()
static void Main()
Dim num As Integer
{
int num; [Link]("Enter a number: ")
num =
[Link]("Enter a number: "); Convert.ToInt32([Link]())
num =
Convert.ToInt32([Link]()); If num > 0 Then
[Link](num & " is
if (num > 0) Positive")
[Link](num + " is ElseIf num < 0 Then
Positive"); [Link](num & " is
Negative")
else if (num < 0) Else
[Link](num + " is [Link]("The number is
Negative"); Zero")
End If
else End Sub
[Link]("The number is End Module
Zero");
}
}
 OUTPUT:  OUTPUT:
PRACTICAL NO. 22
Program: To find grade of the student from marks entered (Console Based)
 CODE:
C# [Link]
// C# Console Program: Find Grade of ' [Link] Console Program: Find Grade
Student of Student
using System; Imports System
class Program Module Module1
Sub Main()
{
Dim marks As Integer
static void Main() Dim grade As String
{
int marks; [Link]("Enter marks of the
string grade; student (0-100): ")
marks =
[Link]("Enter marks of the
Convert.ToInt32([Link]())
student (0-100): ");
marks = If marks >= 90 Then
Convert.ToInt32([Link]()); grade = "A"
ElseIf marks >= 75 Then
if (marks >= 90)
grade = "B"
grade = "A";
ElseIf marks >= 60 Then
else if (marks >= 75)
grade = "C"
grade = "B";
ElseIf marks >= 40 Then
else if (marks >= 60)
grade = "D"
grade = "C";
Else
else if (marks >= 40)
grade = "Fail"
grade = "D";
End If
else
grade = "Fail";
[Link]("Grade: " & grade)
[Link]("Grade: " + grade);
End Sub
} End Module
}
 OUTPUT:  OUTPUT:
PRACTICAL NO. 23
Program: To print multiplication table of a Number (Console Based)
 CODE:
C# [Link]
// C# Console Program: Multiplication ' [Link] Console Program:
Table Multiplication Table
using System; Imports System

Module Module1
class Program
{ Sub Main()
static void Main() Dim num As Integer
{
int num; [Link]("Enter a number: ")
num =
[Link]("Enter a number: "); Convert.ToInt32([Link]())
num =
Convert.ToInt32([Link]()); [Link]("Multiplication
Table of " & num & ":")
[Link]("Multiplication
Table of " + num + ":"); For i As Integer = 1 To 10
[Link](num & " x " & i
for (int i = 1; i <= 10; i++) & " = " & (num * i))
{ Next
[Link](num + " x " + i End Sub
+ " = " + (num * i)); End Module
}
}
}

 OUTPUT:  OUTPUT:
PRACTICAL NO. 24
Program: To print Fibonacci Series (Console Based)
 CODE:
C# [Link]
// C# Console Program: Fibonacci Series ' [Link] Console Program: Fibonacci
Series
using System;
Imports System
class Program
{ Module Module1
static void Main() Sub Main()
{ Dim n, first As Integer
int n, first = 0, second = 1, next; Dim second As Integer = 1
Dim nextTerm As Integer
[Link]("Enter the number of
terms: "); [Link]("Enter the number of
n= terms: ")
Convert.ToInt32([Link]()); n=
Convert.ToInt32([Link]())
[Link]("Fibonacci Series
up to " + n + " terms:"); [Link]("Fibonacci Series
up to " & n & " terms:")
for (int i = 1; i <= n; i++)
{ For i As Integer = 1 To n
[Link](first + " "); [Link](first & " ")
next = first + second; nextTerm = first + second
first = second; first = second
second = next; second = nextTerm
} Next
} End Sub
} End Module

 OUTPUT:  OUTPUT:
PRACTICAL NO. 25
Program: To find Factorial of a number (Console Based)
 CODE:
C# [Link]
// C# Console Program: Factorial of a ' [Link] Console Program: Factorial of
Number a Number
using System; Imports System

class Program Module Module1


{ Sub Main()
static void Main() Dim n As Integer
{ Dim fact As Long = 1
int n;
long fact = 1; [Link]("Enter a number: ")
n=
[Link]("Enter a number: "); Convert.ToInt32([Link]())
n=
Convert.ToInt32([Link]()); For i As Integer = 1 To n
fact *= i
for (int i = 1; i <= n; i++) Next
{
fact *= i; [Link]("Factorial of " & n
} & " is: " & fact)
End Sub
[Link]("Factorial of " + n End Module
+ " is: " + fact);
}
}

 OUTPUT:  OUTPUT:
PRACTICAL NO. 26
Program: To convert temperature from Celsius to Fahrenheit & vice–versa
(Console Based)
 CODE:
// C# Console Program: Temperature Conversion
using System;

class Program
{
static void Main()
{
double celsius, fahrenheit;
int choice;

[Link]("Temperature Conversion");
[Link]("1. Celsius to Fahrenheit");
[Link]("2. Fahrenheit to Celsius");
[Link]("Enter your choice (1 or 2): ");
choice = Convert.ToInt32([Link]());

if (choice == 1)
{
[Link]("Enter temperature in Celsius: ");
celsius = [Link]([Link]());

fahrenheit = (celsius * 9 / 5) + 32;


[Link]("Temperature in Fahrenheit = " + fahrenheit);
}
else if (choice == 2)
{
[Link]("Enter temperature in Fahrenheit: ");
fahrenheit = [Link]([Link]());

celsius = (fahrenheit - 32) * 5 / 9;


[Link]("Temperature in Celsius = " + celsius);
}
else
{
[Link]("Invalid Choice!");
}
}
}
 OUTPUT:

 CODE:
' [Link] Console Program: Temperature Conversion
Imports System
Module Module1
Sub Main()
Dim celsius, fahrenheit As Double
Dim choice As Integer

[Link]("Temperature Conversion")
[Link]("1. Celsius to Fahrenheit")
[Link]("2. Fahrenheit to Celsius")
[Link]("Enter your choice (1 or 2): ")
choice = Convert.ToInt32([Link]())
If choice = 1 Then
[Link]("Enter temperature in Celsius: ")
celsius = [Link]([Link]())
fahrenheit = (celsius * 9 / 5) + 32
[Link]("Temperature in Fahrenheit = " & fahrenheit)
ElseIf choice = 2 Then
[Link]("Enter temperature in Fahrenheit: ")
fahrenheit = [Link]([Link]())
celsius = (fahrenheit - 32) * 5 / 9
[Link]("Temperature in Celsius = " & celsius)
Else
[Link]("Invalid Choice!")
End If
End Sub
End Module
 OUTPUT:
PRACTICAL NO. 27
Program: To print sum of positive numbers, to exit when a -ve number is
entered (Console Based)
 CODE:
C# [Link]
// C# Console Program: Sum of Positive ' [Link] Console Program: Sum of
Numbers until Negative is Entered Positive Numbers until Negative is
Entered
using System;
Imports System
class Program
{ Module Module1
static void Main() Sub Main()
{ Dim num As Integer
int num; Dim sum As Integer = 0
int sum = 0;
[Link]("Enter numbers
[Link]("Enter numbers (enter a negative number to stop):")
(enter a negative number to stop):");
while (true) Do
{ num =
num = Convert.ToInt32([Link]())
Convert.ToInt32([Link]());
If num < 0 Then
if (num < 0) Exit Do
break; // Exit loop End If

sum += num; sum += num


} Loop

[Link]("Sum of positive
[Link]("Sum of positive
numbers = " + sum); numbers = " & sum)
} End Sub
} End Module

 OUTPUT:  OUTPUT:
PRACTICAL NO. 28
Program: To check whether a number lies between 1 to 10 using switch case
(Console Based)
 CODE:
C# [Link]
// C# Console Program: Check if number ' [Link] Console Program: Check if
lies between 1 and 10 using switch number lies between 1 and 10 using
using System; Select Case
class Program Imports System
{
static void Main() Module Module1
{ int num; Sub Main()
[Link]("Enter a number: "); Dim num As Integer
num =
Convert.ToInt32([Link]()); [Link]("Enter a number: ")
switch (num){ num =
case 1: Convert.ToInt32([Link]())
case 2:
case 3: Select Case num
case 4: Case 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
case 5: 'Alternative---Case 1 To 10
case 6: [Link](num & " lies
case 7: between 1 and 10")
case 8: Case Else
case 9: [Link](num & " is
case 10: outside the range 1 to 10")
[Link](num + " lies End Select
between 1 and 10"); End Sub
break; End Module
default:
[Link](num + " is
outside the range 1 to 10");
break;
}}
}
 OUTPUT:  OUTPUT:
PRACTICAL NO. 29
Program: To check whether a number is palindrome or not using while and do-
while loop (Console Based)
 CODE:
C# [Link]
// C# Console Program: Palindrome ' [Link] Console Program: Palindrome
Check using While Loop Check using While Loop
using System; Imports System
class Program Module Module1
{ Sub Main()
static void Main() Dim num, original, reverse, remainder
{ As Integer
int num, original, reverse = 0, reverse = 0
remainder;
[Link]("Enter a number: ")
[Link]("Enter a number: "); num =
num = Convert.ToInt32([Link]())
Convert.ToInt32([Link]()); original = num
original = num;
While num > 0
while (num > 0) remainder = num Mod 10
{ reverse = (reverse * 10) + remainder
remainder = num % 10; num \= 10
reverse = (reverse * 10) + End While
remainder;
num /= 10; If original = reverse Then
[Link](original & " is a
}
Palindrome")
if (original == reverse) Else
[Link](original + " is a [Link](original & " is
Palindrome"); NOT a Palindrome")
else End If
[Link](original + " is End Sub
NOT a Palindrome"); End Module
}
}
 OUTPUT:  OUTPUT:
 CODE:

C# [Link]
// C# Console Program: Palindrome ' [Link] Console Program: Palindrome
Check using Do-While Loop Check using Do-While Loop
using System; Imports System

class Program Module Module1


{ Sub Main()
static void Main() Dim num, original, reverse, remainder
{ As Integer
int num, original, reverse = 0, reverse = 0
remainder;
[Link]("Enter a number: ")
[Link]("Enter a number: "); num =
num = Convert.ToInt32([Link]())
Convert.ToInt32([Link]()); original = num
original = num;
Do
do remainder = num Mod 10
{ reverse = (reverse * 10) + remainder
remainder = num % 10; num \= 10
reverse = (reverse * 10) + Loop While num > 0
remainder;
num /= 10; If original = reverse Then
} while (num > 0); [Link](original & " is a
Palindrome")
if (original == reverse) Else
[Link](original + " is a [Link](original & " is
Palindrome"); NOT a Palindrome")
else End If
[Link](original + " is End Sub
NOT a Palindrome"); End Module
}
}
 OUTPUT:  OUTPUT:
PRACTICAL NO. 30
Program: To find sum of digits of a number using while and do-while loop
(Console Based)
 CODE:
C# [Link]
// C# Console Program: Sum of Digits ' [Link] Console Program: Sum of
using While Loop Digits using While Loop
using System; Imports System

class Program Module Module1


{ Sub Main()
static void Main() Dim num, sum, remainder As Integer
{ sum = 0
int num, sum = 0, remainder;
[Link]("Enter a number: ")
[Link]("Enter a number: "); num =
num = Convert.ToInt32([Link]())
Convert.ToInt32([Link]());
While num > 0
while (num > 0) remainder = num Mod 10
{ sum += remainder
remainder = num % 10; num \= 10
sum += remainder; End While
num /= 10;
} [Link]("Sum of digits = "
& sum)
[Link]("Sum of digits = " End Sub
+ sum); End Module
}
}

 OUTPUT:  OUTPUT:
 CODE:
C# [Link]
// C# Console Program: Sum of Digits ' [Link] Console Program: Sum of
using Do-While Loop Digits using Do-While Loop
using System; Imports System

class Program Module Module1


{ Sub Main()
static void Main() Dim num, sum, remainder As Integer
{ sum = 0
int num, sum = 0, remainder;
[Link]("Enter a number: ")
[Link]("Enter a number: "); num =
num = Convert.ToInt32([Link]())
Convert.ToInt32([Link]());
Do
do remainder = num Mod 10
{ sum += remainder
remainder = num % 10; num \= 10
sum += remainder; Loop While num > 0
num /= 10;
} while (num > 0); [Link]("Sum of digits = "
& sum)
[Link]("Sum of digits = " End Sub
+ sum); End Module
}
}

 OUTPUT:  OUTPUT:
PRACTICAL NO. 31
Program: To print Reverse of a number (Console Based)
 CODE:
C# [Link]
// C# Console Program: Reverse of a ' [Link] Console Program: Reverse of
Number a Number
using System; Imports System

class Program Module Module1


{ Sub Main()
static void Main() Dim num, reverse, remainder As
{ Integer
int num, reverse = 0, remainder; reverse = 0

[Link]("Enter a number: "); [Link]("Enter a number: ")


num = num =
Convert.ToInt32([Link]()); Convert.ToInt32([Link]())

while (num > 0) While num > 0


{ remainder = num Mod 10
remainder = num % 10; reverse = (reverse * 10) + remainder
reverse = (reverse * 10) + num \= 10
remainder; End While
num /= 10;
} [Link]("Reversed Number
= " & reverse)
[Link]("Reversed Number End Sub
= " + reverse); End Module
}
}

 OUTPUT:  OUTPUT:
PRACTICAL NO. 32
Program: To check whether a number is an Armstrong number or not (Console
Based)
 CODE:
C# [Link]
// C# Console Program: Armstrong ' [Link] Console Program: Armstrong
Number Check Number Check
using System; Imports System
class Program Module Module1
{ Sub Main()
static void Main() Dim num, original, remainder, sum As
{ Integer
int num, original, remainder, sum = 0; sum = 0
[Link]("Enter a number: ")
[Link]("Enter a number: ");
num = num =
Convert.ToInt32([Link]()); Convert.ToInt32([Link]())
original = num; original = num
While num > 0
while (num > 0) remainder = num Mod 10
{ sum += (remainder * remainder *
remainder = num % 10; remainder) ' cube of digit
sum += (remainder * remainder * num \= 10
remainder); // cube of digit End While
num /= 10;
} If sum = original Then
if (sum == original) [Link](original & " is
[Link](original + " is an an Armstrong Number")
Armstrong Number"); Else
else [Link](original & " is
[Link](original + " is NOT an Armstrong Number")
NOT an Armstrong Number"); End If
} End Sub
} End Module
 OUTPUT:  OUTPUT:
PRACTICAL NO. 33
Program: To print Armstrong numbers lies between 1 to 1000 using For loop
(Console Based)
 CODE:
// C# Console Program: Armstrong Numbers from 1 to 1000
using System;
class Program
{
static void Main()
{
[Link]("Armstrong numbers between 1 and 1000:");
for (int num = 1; num <= 1000; num++)
{
int temp = num, remainder, n = 0;
int sum = 0; // changed from double → int
// Count digits
int countDigits = temp;
while (countDigits > 0)
{
n++;
countDigits /= 10; }
// Calculate sum of digits^n
temp = num;
while (temp > 0)
{
remainder = temp % 10;
sum += (int)[Link](remainder, n); // force result back to int
temp /= 10; }
if (sum == num)
[Link](num);
} } }
 OUTPUT:
ALTERNATE:
 CODE:
using System;
class Program
{
static void Main()
{
[Link]("3-digit Armstrong numbers between 100 and 1000:");
for (int num = 100; num <= 999; num++) // restrict to 3-digit numbers
{
int temp = num, remainder;
int sum = 0;
while (temp > 0)
{
remainder = temp % 10;
sum += remainder * remainder * remainder; // cube
temp /= 10;
}
if (sum == num)
[Link](num);
}
}
}

 OUTPUT:
 CODE:
' [Link] Console Program: Armstrong Numbers between 1 and 1000
Imports System
Module Module1
Sub Main()
[Link]("Armstrong numbers between 1 and 1000:")
For num As Integer = 1 To 1000
Dim temp As Integer = num
Dim remainder As Integer
Dim n As Integer = 0
Dim sum As Integer = 0
' Count digits
Dim countDigits As Integer = temp
While countDigits > 0
n += 1
countDigits \= 10
End While
' Calculate sum of digits^n
temp = num
While temp > 0
remainder = temp Mod 10
sum += CInt([Link](remainder, n)) ' cast back to Integer
temp \= 10
End While
If sum = num Then
[Link](num)
End If
Next
End Sub
End Module
 OUTPUT:
ALTERNATE:
 CODE:
' [Link] Console Program: Armstrong Numbers from 100 to 999
Imports System
Module Module1
Sub Main()
[Link]("3-digit Armstrong numbers between 100 and 1000:")

For num As Integer = 100 To 999


Dim temp As Integer = num
Dim remainder As Integer
Dim sum As Integer = 0

While temp > 0


remainder = temp Mod 10
sum += remainder * remainder * remainder ' cube
temp \= 10
End While
If sum = num Then
[Link](num)
End If
Next
End Sub
End Module
 OUTPUT:
PRACTICAL NO. 34
Program: To demonstrate the use of Nested Switch case (Console Based)
 CODE:
// C# Console Program: Nested Switch Case
using System;
class Program
{
static void Main()
{
int mainChoice, subChoice;

[Link]("Main Menu:");
[Link]("1. Check Number Type");
[Link]("2. Exit");
[Link]("Enter choice: ");
mainChoice = Convert.ToInt32([Link]());

switch (mainChoice)
{
case 1:
[Link]("Sub Menu:");
[Link]("1. Even or Odd");
[Link]("2. Positive or Negative");
[Link]("Enter sub-choice: ");
subChoice = Convert.ToInt32([Link]());

[Link]("Enter a number: ");


int num = Convert.ToInt32([Link]());

switch (subChoice)
{
case 1:
[Link](num % 2 == 0 ? "Even Number" : "Odd Number");
break;
case 2:
if (num > 0)
[Link]("Positive Number");
else if (num < 0)
[Link]("Negative Number");
else
[Link]("Zero");
break;
default:
[Link]("Invalid Sub-Choice");
break;
}
break;

case 2:
[Link]("Exiting...");
break;

default:
[Link]("Invalid Main Choice");
break;
}
}
}

 OUTPUT:
 CODE:
' [Link] Console Program: Nested Select Case
Imports System
Module Module1
Sub Main()
Dim mainChoice, subChoice, num As Integer

[Link]("Main Menu:")
[Link]("1. Check Number Type")
[Link]("2. Exit")
[Link]("Enter choice: ")
mainChoice = Convert.ToInt32([Link]())

Select Case mainChoice


Case 1
[Link]("Sub Menu:")
[Link]("1. Even or Odd")
[Link]("2. Positive or Negative")
[Link]("Enter sub-choice: ")
subChoice = Convert.ToInt32([Link]())

[Link]("Enter a number: ")


num = Convert.ToInt32([Link]())

Select Case subChoice


Case 1
If num Mod 2 = 0 Then
[Link]("Even Number")
Else
[Link]("Odd Number")
End If
Case 2
If num > 0 Then
[Link]("Positive Number")
ElseIf num < 0 Then
[Link]("Negative Number")
Else
[Link]("Zero")
End If
Case Else
[Link]("Invalid Sub-Choice")
End Select
Case 2
[Link]("Exiting...")

Case Else
[Link]("Invalid Main Choice")
End Select
End Sub
End Module

 OUTPUT:
PRACTICAL NO. 35
Program: To demonstrate the use of Operators (Unary, Binary, Ternary)
(Console Based)
 CODE:
// C# Console Program: Demonstrating Unary, Binary, and Ternary Operators
using System;

class Program
{
static void Main()
{
int a = 10, b = 5;

[Link]("Demonstration of Operators");

// Unary Operators
[Link]("\n--- Unary Operators ---");
[Link]("Initial a = " + a);
[Link]("Post-increment a++ = " + (a++));
[Link]("After post-increment, a = " + a);
[Link]("Pre-decrement --b = " + (--b));

// Binary Operators
[Link]("\n--- Binary Operators ---");
[Link]("a + b = " + (a + b));
[Link]("a - b = " + (a - b));
[Link]("a * b = " + (a * b));
[Link]("a / b = " + (a / b));

// Ternary Operator
[Link]("\n--- Ternary Operator ---");
int max = (a > b) ? a : b;
[Link]("Greater of a and b = " + max);

[Link]();
}
}
 OUTPUT:

 CODE:
' [Link] Console Program: Demonstrating Unary, Binary, and Ternary
Operators
Imports System
Module OperatorsDemo
Sub Main()
Dim a As Integer = 10
Dim b As Integer = 5
Dim result As Integer
[Link]("--- Demonstration of Operators in [Link] ---")
' Unary Operators
[Link]()
[Link]("--- Unary Operators ---")
[Link]("Initial value of a = " & a)
result = -a
[Link]("Unary minus (-a) = " & result)
result = +a
[Link]("Unary plus (+a) = " & result)
[Link]("Logical Not of True = " & Not True)
a += 1
[Link]("After a += 1, a = " & a)
b -= 1
[Link]("After b -= 1, b = " & b)
' Binary Operators
[Link]()
[Link]("--- Binary Operators ---")
[Link]("a + b = " & (a + b))
[Link]("a - b = " & (a - b))
[Link]("a * b = " & (a * b))
[Link]("a / b = " & (a / b)) ' floating-point division
[Link]("a \ b = " & (a \ b)) ' integer division
[Link]("a Mod b = " & (a Mod b))
[Link]("a ^ b = " & (a ^ b)) ' power
' Ternary Operator
[Link]()
[Link]("--- Ternary Operator ---")
Dim max As Integer = If(a > b, a, b)
[Link]("Greater of a and b = " & max)
[Link]()
End Sub
End Module

 OUTPUT:

Note:
 The Ternary Operator (? :) in C# is also known as the Conditional Operator.
 It works as a shorthand for if...else statements.
 Example: In C#
int max = (a > b) ? a : b;
 In [Link], the conditional check is done using the If(condition, truePart,
falsePart) function instead of ? : .
PRACTICAL NO. 36
Program: To demonstrate the use of Null-coalescing operator – C# (Console
Based)
 CODE:
// C# Console Program: Demonstrating Null-coalescing operator (??)
using System;
class Program
{
static void Main() {
[Link]("--- Demonstration of Null-coalescing Operator in C# ---\n");
string name1 = null;
string name2 = "Mukesh";
// Using ?? operator
string result1 = name1 ?? "Default Name";
string result2 = name2 ?? "Default Name";
[Link]("name1 is null, so result1 = " + result1);
[Link]("name2 is not null, so result2 = " + result2);
// Example with nullable integers
int? num1 = null;
int? num2 = 25;
int numberResult1 = num1 ?? -1; // if null, take -1
int numberResult2 = num2 ?? -1; // if not null, take num2
[Link]("\nnum1 is null, so numberResult1 = " + numberResult1);
[Link]("num2 is not null, so numberResult2 = " + numberResult2);
[Link](); }
}

 OUTPUT:
PRACTICAL NO. 37
Program: To demonstrate the use of Null-coalescing assignment operator – C#
(Console Based)
 CODE:
// C# Console Program: Demonstrating Null-coalescing Assignment Operator (??=)
using System;

class Program
{
static void Main()
{
[Link]("--- Demonstration of Null-coalescing Assignment Operator
(??=) ---\n");

string name1 = null;


string name2 = "Mukesh";

// Using ??= operator


name1 ??= "Default Name"; // assigns because name1 is null
name2 ??= "Default Name"; // does not assign because name2 already has a value

[Link]("Value of name1 after ??= : " + name1);


[Link]("Value of name2 after ??= : " + name2);

// Example with nullable integer


int? num1 = null;
int? num2 = 50;

num1 ??= -1; // assigns -1 because num1 is null


num2 ??= -1; // no assignment, since num2 is already 50

[Link]("\nValue of num1 after ??= : " + num1);


[Link]("Value of num2 after ??= : " + num2);

[Link]();
}
}
 OUTPUT:

NOTE: Comparison: Null-coalescing Operator (??) vs Null-coalescing


Assignment Operator (??=)

Feature / ?? (Null-coalescing) ??= (Null-coalescing Assignment)


Operator
Introduced in C# 2.0 C# 8.0
Usage Provides a fallback/default value if Assigns a value to the variable only
the left-hand operand is null if it is currently null
Syntax result = value1 ?? value2; variable ??= defaultValue;
Behavior Returns the right-hand operand Modifies the left-hand operand by
only when the left-hand operand is assigning it the right-hand value if it
null is null
Example string result = name ?? "Guest"; name ??= "Guest";
Effect Does not change the original Changes the original variable if it
variable (just provides a value for was null
use)
Sample If name = null, then result = If name = null, then name becomes
Result "Guest" (but name remains null) "Guest"

Summary:
 Use ?? when you want to use a default value temporarily.
 Use ??= when you want to store a default value permanently in a variable if it was
null.
PRACTICAL NO. 38
Program: To demonstrate the use of Simple Class & Object (Console Based)
 CODE:
// C# Console Program: Demonstrate Simple Class and Object
using System;
class Student {
// Fields
public int RollNo;
public string Name;

// Method
public void DisplayDetails() {
[Link]("Roll No: " + RollNo);
[Link]("Name : " + Name);
}
}
class Program
{
static void Main()
{
// Creating object of Student class
Student s1 = new Student();
[Link] = 43;
[Link] = "Mukesh Aggarwal";

[Link]("--- Student Details (C#) ---");


[Link]();
[Link](); }
}

 OUTPUT:
 CODE:
' [Link] Console Program: Demonstrate Simple Class and Object
Imports System

Class Student
' Fields
Public RollNo As Integer
Public Name As String

' Method
Public Sub DisplayDetails()
[Link]("Roll No: " & RollNo)
[Link]("Name : " & Name)
End Sub
End Class

Module Program
Sub Main()
' Creating object of Student class
Dim s1 As New Student()
[Link] = 101
[Link] = "Rahul"

[Link]("--- Student Details ([Link]) ---")


[Link]()

[Link]()
End Sub
End Module

 OUTPUT:
PRACTICAL NO. 39
Program: To demonstrate the use of Static Class (Console Based)
 CODE:
// C# Console Program: Demonstrating Static Class
using System;
static class Calculator {
public static int Add(int a, int b)
{
return a + b;
}
public static int Multiply(int a, int b)
{
return a * b;
}
}
class Program {
static void Main() {
[Link]("--- Demonstration of Static Class in C# ---");
// Directly call static methods without creating an object
int sum = [Link](10, 20);
int product = [Link](5, 6);
[Link]("Sum = " + sum);
[Link]("Product = " + product);
[Link](); }
}

 OUTPUT:
 CODE:
' [Link] Console Program: Demonstrating Static Class using Module
Imports System

Module Calculator
' Shared methods (implicitly static in Module)
Public Function Add(a As Integer, b As Integer) As Integer
Return a + b
End Function

Public Function Multiply(a As Integer, b As Integer) As Integer


Return a * b
End Function
End Module

Module Program
Sub Main()
[Link]("--- Demonstration of Static Class in [Link] ---")

' Directly call methods without creating an object


Dim sum As Integer = [Link](10, 20)
Dim product As Integer = [Link](5, 6)

[Link]("Sum = " & sum)


[Link]("Product = " & product)

[Link]()
End Sub
End Module

 OUTPUT:
PRACTICAL NO. 40
Program: To demonstrate the use of Abstract Class (Console Based)
 CODE:
// C# Console Program: Demonstrating Abstract Class
using System;

abstract class Shape


{
public abstract double Area(); // Abstract method
public void Display()
{
[Link]("This is a shape.");
}
}
class Rectangle : Shape
{
public double Length { get; set; }
public double Width { get; set; }

public Rectangle(double l, double w)


{
Length = l;
Width = w;
}
// Implementing abstract method
public override double Area()
{
return Length * Width;
}
}
class Program
{
static void Main()
{
[Link]("--- Demonstration of Abstract Class in C# ---");

Shape shape = new Rectangle(10, 5);


[Link]();
[Link]("Area of Rectangle = " + [Link]());

[Link]();
}
}
 OUTPUT:

 CODE:
' [Link] Console Program: Demonstrating Abstract Class
Imports System

MustInherit Class Shape


' Abstract method (MustOverride)
Public MustOverride Function Area() As Double

' Concrete method


Public Sub Display()
[Link]("This is a shape.")
End Sub
End Class

Class Rectangle
Inherits Shape

Public Property Length As Double


Public Property Width As Double

Public Sub New(l As Double, w As Double)


Length = l
Width = w
End Sub

' Implementing abstract method


Public Overrides Function Area() As Double
Return Length * Width
End Function
End Class

Module Program
Sub Main()
[Link]("--- Demonstration of Abstract Class in [Link] ---")

Dim shape As Shape = New Rectangle(10, 5)


[Link]()
[Link]("Area of Rectangle = " & [Link]())

[Link]()
End Sub
End Module

 OUTPUT:
PRACTICAL NO. 41
Program: To demonstrate the use of Sealed Class (Console Based)
 CODE:
// C# Console Program: Demonstrating Sealed Class
using System;
// Sealed class
sealed class Calculator
{
public int Add(int a, int b)
{
return a + b;
}
public int Multiply(int a, int b)
{
return a * b;
}
}
class Program{
static void Main()
{
[Link]("--- Demonstration of Sealed Class in C# ---");
Calculator calc = new Calculator();
[Link]("Sum = " + [Link](10, 20));
[Link]("Product = " + [Link](5, 6));
[Link](); }
}

 OUTPUT:
 CODE:
' [Link] Console Program: Demonstrating Sealed Class
Imports System
' Sealed class in [Link] (NotInheritable)
NotInheritable Class Calculator
Public Function Add(a As Integer, b As Integer) As Integer
Return a + b
End Function

Public Function Multiply(a As Integer, b As Integer) As Integer


Return a * b
End Function
End Class
Module Program
Sub Main()
[Link]("--- Demonstration of Sealed Class in [Link] ---")
Dim calc As New Calculator()
[Link]("Sum = " & [Link](10, 20))
[Link]("Product = " & [Link](5, 6))

[Link]()
End Sub
End Module
 OUTPUT:
PRACTICAL NO. 42
Program: To demonstrate the use of Partial Class (Console Based)
 CODE:
// C# Console Program: Demonstrating Partial Class
using System;
// First part of the partial class
partial class Student
{
public int RollNo;
public string Name;
public void DisplayBasicInfo()
{
[Link]("Roll No: " + RollNo);
[Link]("Name : " + Name);
}
}
// Second part of the partial class
partial class Student
{
public int Marks;
public void DisplayMarks()
{
[Link]("Marks : " + Marks);
}
}
class Program
{
static void Main()
{
[Link]("--- Demonstration of Partial Class in C# ---");
Student s1 = new Student();
[Link] = 101;
[Link] = "Mukesh Aggarwal";
[Link] = 85;
[Link]();
[Link]();
[Link]();
}
}
 OUTPUT:

 CODE:
' [Link] Console Program: Demonstrating Partial Class
Imports System

' First part of the partial class


Partial Class Student
Public RollNo As Integer
Public Name As String

Public Sub DisplayBasicInfo()


[Link]("Roll No: " & RollNo)
[Link]("Name : " & Name)
End Sub
End Class

' Second part of the partial class


Partial Class Student
Public Marks As Integer

Public Sub DisplayMarks()


[Link]("Marks : " & Marks)
End Sub
End Class

Module Program
Sub Main()
[Link]("--- Demonstration of Partial Class in [Link] ---")

Dim s1 As New Student()


[Link] = 102
[Link] = "Vikram Singh"
[Link] = 75

[Link]()
[Link]()

[Link]()
End Sub
End Module

 OUTPUT:
PRACTICAL NO. 43
Program: To demonstrate the use of Nested Class (Console Based)
 CODE:
// C# Console Program: Demonstrating Nested Class
using System;

class Outer
{
private string message = "Hello from Outer Class!";

// Nested Class
public class Inner
{
public void ShowMessage()
{
[Link]("Hello from Inner Class!");
}
}
public void ShowOuterMessage()
{
[Link](message);
}
}
class Program
{
static void Main()
{
[Link]("--- Demonstration of Nested Class in C# ---");

// Create object of Outer class


Outer outer = new Outer();
[Link]();

// Create object of Inner class (using [Link])


[Link] inner = new [Link]();
[Link]();

[Link]();
}
}
 OUTPUT:

 CODE:
' [Link] Console Program: Demonstrating Nested Class
Imports System

Class Outer
Private message As String = "Hello from Outer Class!"

' Nested Class


Public Class Inner
Public Sub ShowMessage()
[Link]("Hello from Inner Class!")
End Sub
End Class

Public Sub ShowOuterMessage()


[Link](message)
End Sub
End Class

Module Program
Sub Main()
[Link]("--- Demonstration of Nested Class in [Link] ---")

' Create object of Outer class


Dim outer As New Outer()
[Link]()

' Create object of Inner class (using [Link])


Dim inner As New [Link]()
[Link]()

[Link]()
End Sub
End Module

 OUTPUT:
PRACTICAL NO. 44
Program: To demonstrate the use of Single Inheritance (Console Based)
 CODE:
// C# Console Program: Demonstrating Single Inheritance
using System;

class Animal
{
public virtual void MakeSound()
{
[Link]("Animal makes different sounds");
}
}
class Dog : Animal
{
public override void MakeSound()
{
[Link]("Bhow Bhow");
}
}
class Test
{
public static void Main()
{
Dog d1 = new Dog();
[Link]();
}
}

 OUTPUT:
 CODE:
' [Link] Console Program: Demonstrating Single Inheritance
Module Module1
Public Class Animal
Public Overridable Sub MakeSound()
[Link]("Animals make different sounds")
End Sub
End Class

Public Class Dog


Inherits Animal
Public Overrides Sub MakeSound()
[Link]("Woof! Woof!")
End Sub
End Class

Sub Main()
Dim d1 As New Dog
[Link]()
End Sub
End Module

 OUTPUT:
PRACTICAL NO. 45
Program: To demonstrate the use of Multilevel Inheritance (Console Based)
 CODE:
// C# Console Program: Demonstrating Multilevel Inheritance
using System;

class Animal
{
public virtual void makesound()
{
[Link]("Animal makes different sound");
}
}
class Dog : Animal
{
public override void makesound()
{
[Link]("Woof Woof");
}
}
class Puppy : Dog
{
public void legCount()
{
[Link]("Puppy has 4 legs");
}
}
class Test
{
public static void Main()
{
Dog d1 = new Dog();
Puppy p1 = new Puppy();

[Link](); // Output: Bhow Bhow


[Link](); // Output: Bhow Bhow
[Link](); // Output: Puppy has 4 legs
}
}
 OUTPUT:

 CODE:
' [Link] Console Program: Demonstrating Multilevel Inheritance
Imports System
Module Module1

Public Class Animal


Public Overridable Sub makesound()
[Link]("Animals Make different sound")
End Sub
End Class

Public Class Dog


Inherits Animal
Public Overrides Sub makesound()
[Link]("Woof Woof")
End Sub
End Class

Public Class Puppy


Inherits Dog
Public Sub legCount()
[Link]("Puppy has 4 legs")
End Sub

End Class
Sub main()
Dim d1 As New Dog
Dim d2 As New Puppy

[Link]()
[Link]()
[Link]()
End Sub

End Module

 OUTPUT:
PRACTICAL NO. 46
Program: To demonstrate the use of Hierarchical Inheritance (Console Based)
 CODE:
// C# Console Program: Demonstrating hierarchical Inheritance
using System;

class Animal
{
public virtual void makesound()
{
[Link]("Animal makes different sound");
}
}
class Dog : Animal
{
public override void makesound()
{
[Link]("Woof Woof");
}
}
class Cat : Animal
{
public override void makesound()
{
[Link]("Meow Meow");
}
}
class Test
{
public static void Main()
{
Dog d1 = new Dog();
Cat c1 = new Cat();

[Link](); // Output: Woof Woof


[Link](); // Output: Meow Meow
}
}
 OUTPUT:

 CODE:
' [Link] Console Program: Demonstrating hierarchical Inheritance
Imports System

Module Module1

Public Class Animal


Public Overridable Sub makesound()
[Link]("Animal Makes different sounds")
End Sub
End Class

Public Class Dog


Inherits Animal
Public Overrides Sub makesound()
[Link]("Woof Woof")
End Sub
End Class

Public Class Cat


Inherits Animal
Public Overrides Sub makesound()
[Link]("Meow Meow")
End Sub
End Class

Sub main()
Dim d1 As New Dog
Dim c1 As New Cat
[Link]() ' Output: Woof Woof
[Link]() ' Output: Meow Meow
End Sub

End Module

 OUTPUT:
PRACTICAL NO. 47
Program: To demonstrate the use of Hybrid Inheritance (Console Based)
 CODE:
// C# Console Program: Demonstrating hybrid Inheritance
using System;

class Animal
{
public virtual void MakeSound()
{
[Link]("Animal makes different sounds");
}
}
class Dog : Animal
{
public override void MakeSound()
{
[Link]("Woof Woof");
}
}
class Puppy : Dog
{
public void LegCount()
{
[Link]("Puppy has 4 legs");
}
}
class Cat : Animal
{
public override void MakeSound()
{
[Link]("Meow Meow");
}
}
class Kitty : Cat
{
public void LegCount()
{
[Link]("Kitty has 4 legs");
}
}
class Test
{
public static void Main()
{
Dog d1 = new Dog();
Puppy p1 = new Puppy();
Cat c1 = new Cat();
Kitty k1 = new Kitty();

[Link]();
[Link]();

[Link]();
[Link]();
[Link]();
}
}

 OUTPUT:
 CODE:
' [Link] Console Program: Demonstrating hybrid Inheritance
Imports System

Module Module1
Public Class Animal
Public Overridable Sub MakeSound()
[Link]("Animals make different sounds")
End Sub
End Class

Public Class Dog


Inherits Animal
Public Overrides Sub MakeSound()
[Link]("Woof Woof")
End Sub
End Class

Public Class Puppy


Inherits Dog
Public Sub LegCount()
[Link]("Puppy has 4 legs")
End Sub
End Class

Public Class Cat


Inherits Animal
Public Overrides Sub MakeSound()
[Link]("Meow Meow")
End Sub
End Class

Public Class Kitty


Inherits Cat
Public Sub LegCount()
[Link]("Kitty has 4 legs")
End Sub
End Class

Sub Main()
Dim d1 As New Dog
Dim p1 As New Puppy
Dim c1 As New Cat
Dim k1 As New Kitty
[Link]()
[Link]()

[Link]()
[Link]()
[Link]()
End Sub
End Module

 OUTPUT:
PRACTICAL NO. 48
Program: To demonstrate the use of Multiple Inheritance (using Interfaces)
(Console Based)
 CODE:
// C# Console Program: Demonstrating multiple Inheritance using Interfaces
using System;
interface IAnimal {
void Eat();
}
interface IPet {
void Play();
}
class Dog : IAnimal, IPet
{
public void Eat()
{
[Link]("Dog is Eating");
}
public void Play()
{
[Link]("Dog is Playing");
}
}
class Program {
static void Main()
{
Dog d = new Dog();
[Link]();
[Link]();
}
}
 OUTPUT:
 CODE:
' [Link] Console Program: Demonstrating multiple Inheritance using Interfaces
Module Module1
Public Interface IAnimal
Sub Eat()
End Interface
Public Interface IPet
Sub Play()
End Interface
Public Class Dog
Implements IAnimal, IPet
Public Sub Eat() Implements [Link]
[Link]("Dog is Eating")
End Sub
Public Sub Play() Implements [Link]
[Link]("Dog is Playing")
End Sub
End Class
Sub Main()
Dim d As New Dog()
[Link]()
[Link]()
End Sub
End Module

 OUTPUT:
PRACTICAL NO. 49
Program: To demonstrate the use of ArrayList (Console Based)
 CODE:
// C# Console Program: Demonstrating use of ArrayList
using System;
using [Link];
class Program
{
static void Main()
{
ArrayList myList = new ArrayList();
// Adding elements
[Link]("Apple");
[Link]("Banana");
[Link]("Cherry");
[Link](100);
[Link]("ArrayList elements:");
// Traversing ArrayList
foreach (var item in myList)
{
[Link](item);
}
}
}

 OUTPUT:
 CODE:
' [Link] Console Program: Demonstrating use of ArrayList
Imports [Link]

Module Program
Sub Main()
Dim myList As New ArrayList()

' Adding elements


[Link]("Apple")
[Link]("Banana")
[Link]("Cherry")
[Link](100)

[Link]("ArrayList elements:")

' Traversing ArrayList


For Each item In myList
[Link](item)
Next

[Link]()
End Sub
End Module

 OUTPUT:
PRACTICAL NO. 50
Program: To demonstrate the use of Dictionary (Console Based)
 CODE:
// C# Console Program: Demonstrating use of Dictionary
using System;
using [Link];

class Program
{
static void Main()
{
Dictionary<int, string> students = new Dictionary<int, string>();

// Adding roll numbers with student names


[Link](101, "Mukesh");
[Link](102, "Shivam");
[Link](103, "Vishal");
[Link](104, "Himanshu");

[Link]("Student Records (Roll No -> Name):");

// Traversing Dictionary
foreach (KeyValuePair<int, string> kvp in students)
{
[Link]([Link] + " -> " + [Link]);
}
}
}

 OUTPUT:
 CODE:
' [Link] Console Program: Demonstrating use of Dictionary
Imports [Link]

Module Program
Sub Main()
Dim students As New Dictionary(Of Integer, String)()

' Adding roll numbers with student names


[Link](101, "Mukesh")
[Link](102, "Shivam")
[Link](103, "Vishal")
[Link](104, "Himanshu")

[Link]("Student Records (Roll No -> Name):")

' Traversing Dictionary


For Each kvp As KeyValuePair(Of Integer, String) In students
[Link]([Link] & " -> " & [Link])
Next

[Link]()
End Sub
End Module

 OUTPUT:
PRACTICAL NO. 51
Program: To demonstrate the use of HashTable (Console Based)
 CODE:
// C# Console Program: Demonstrating use of HashTable
using System;
using [Link];

class Program
{
static void Main()
{
Hashtable ht = new Hashtable();

// Adding key-value pairs


[Link](1, "Apple");
[Link](2, "Banana");
[Link](3, "Cherry");
[Link](4, "Mango");

[Link]("Hashtable Elements:");

// Traversing Hashtable
foreach (DictionaryEntry item in ht)
{
[Link]([Link] + " -> " + [Link]);
}
}
}

 OUTPUT:
 CODE:
' [Link] Console Program: Demonstrating use of HashTable
Imports [Link]

Module Program
Sub Main()
Dim ht As New Hashtable()

' Adding key-value pairs


[Link](1, "Apple")
[Link](2, "Banana")
[Link](3, "Cherry")
[Link](4, "Mango")

[Link]("Hashtable Elements:")

' Traversing Hashtable


For Each item As DictionaryEntry In ht
[Link]([Link] & " -> " & [Link])
Next

[Link]()
End Sub
End Module

 OUTPUT:
PRACTICAL NO. 52
Program: To demonstrate the use of List (Console Based)
 CODE:
// C# Console Program: Demonstrating use of List
using System;
using [Link];

class Program
{
static void Main()
{
List<string> fruits = new List<string>();
// Adding elements
[Link]("Apple");
[Link]("Banana");
[Link]("Cherry");
[Link]("Mango");
[Link]("List Elements:");
// Traversing list
foreach (string fruit in fruits)
{
[Link](fruit);
}
// Accessing by index
[Link]("\nSecond Element: " + fruits[1]);
}
}

 OUTPUT:
 CODE:
' [Link] Console Program: Demonstrating use of List
Imports [Link]

Module Program
Sub Main()
Dim fruits As New List(Of String)()

' Adding elements


[Link]("Apple")
[Link]("Banana")
[Link]("Cherry")
[Link]("Mango")

[Link]("List Elements:")

' Traversing list


For Each fruit As String In fruits
[Link](fruit)
Next

' Accessing by index


[Link](vbCrLf & "Second Element: " & fruits(1))

[Link]()
End Sub
End Module

 OUTPUT:

You might also like