.NET Projects and IDE Overview Guide
.NET Projects and IDE Overview Guide
NET LAB
FILE
J.C. BOSE UNIVERSITY OF
SCIENCE AND
TECHNOLOGY, YMCA
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:
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.
The image below shows the Visual Studio IDE, highlighting key areas and tools that
assist in software development:
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.
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
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:
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.
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.
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.
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
2. Reference Types
Reference types store the memory address of data (heap). Multiple variables can
reference the same object.
3. Nullable Types
Value types can be made nullable using ?, allowing them to represent an undefined
value.
4. Dynamic Type
Introduced in C# 4.0, allows variables to store any type, with type checking deferred
until runtime.
Declared using the var keyword. The compiler infers the type at compile time.
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.
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#.
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
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
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]())
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
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
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])
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
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
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
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;
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!");
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
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
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");
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
class Program
{
static void Main()
{
double a, b;
char op;
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
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
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
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]());
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
[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
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
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
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:")
[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]());
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]())
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");
[Link]();
}
}
OUTPUT:
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";
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]()
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
Module Program
Sub Main()
[Link]("--- Demonstration of Static Class in [Link] ---")
[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;
[Link]();
}
}
OUTPUT:
CODE:
' [Link] Console Program: Demonstrating Abstract Class
Imports System
Class Rectangle
Inherits Shape
Module Program
Sub Main()
[Link]("--- Demonstration of Abstract Class in [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
[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
Module Program
Sub Main()
[Link]("--- Demonstration of Partial Class in [Link] ---")
[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# ---");
[Link]();
}
}
OUTPUT:
CODE:
' [Link] Console Program: Demonstrating Nested Class
Imports System
Class Outer
Private message As String = "Hello from Outer Class!"
Module Program
Sub Main()
[Link]("--- Demonstration of Nested Class in [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
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();
CODE:
' [Link] Console Program: Demonstrating Multilevel Inheritance
Imports System
Module Module1
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();
CODE:
' [Link] Console Program: Demonstrating hierarchical Inheritance
Imports System
Module Module1
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
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()
[Link]("ArrayList elements:")
[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>();
// 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)()
[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();
[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()
[Link]("Hashtable Elements:")
[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)()
[Link]("List Elements:")
[Link]()
End Sub
End Module
OUTPUT: