Net LAB Manual
Net LAB Manual
RecognisedunderUGCSection(2f)oftheUGCAct1956
Lab Manual
EXPERIMENT-1
Steps:
Code:
using System;
class Program {
Console.WriteLine("Hello, World!");
Output:
Hello, World!
Page 1 of 20
SHIVALIKCOLLEGEOFENGINEERING
RecognisedunderUGCSection(2f)oftheUGCAct1956
EXPERIMENT-2
Code:
using System;
class ArithmeticOperations
Console.WriteLine();
double result = 0;
switch (operation)
Page 2 of 20
SHIVALIKCOLLEGEOFENGINEERING
RecognisedunderUGCSection(2f)oftheUGCAct1956
Console.WriteLine($"Result: {result}");
Output:
Enter two numbers:
5
3
Choose an operation: +
Result: 8
Page 3 of 20
SHIVALIKCOLLEGEOFENGINEERING
RecognisedunderUGCSection(2f)oftheUGCAct1956
EXPERIMENT-3
Output:
Enter a number:
5
Factorial of 5 is 120
Page 4 of 20
SHIVALIKCOLLEGEOFENGINEERING
RecognisedunderUGCSection(2f)oftheUGCAct1956
EXPERIMENT-4
Code:
using System;
class Student
class Program
Page 5 of 20
SHIVALIKCOLLEGEOFENGINEERING
RecognisedunderUGCSection(2f)oftheUGCAct1956
student.DisplayDetails();
Output:
Page 6 of 20
SHIVALIKCOLLEGEOFENGINEERING
RecognisedunderUGCSection(2f)oftheUGCAct1956
EXPERIMENT-5
Objective: Demonstrate method overriding and use of the virtual and override
keywords.
Code-:
using System;
class Animal
Console.WriteLine("Animal speaks");
Console.WriteLine("Dog barks");
class Program
Page 7 of 20
SHIVALIKCOLLEGEOFENGINEERING
RecognisedunderUGCSection(2f)oftheUGCAct1956
animal.Speak();
dog.Speak();
polymorphicAnimal.Speak();
Output:
Animal speaks
Dog barks
Dog barks
Page 8 of 20
SHIVALIKCOLLEGEOFENGINEERING
RecognisedunderUGCSection(2f)oftheUGCAct1956
EXPERIMENT- 6
Objective: Create a BankAccount class with private fields and public properties.
Code-:
using System;
class BankAccount
set
if (value >= 0)
balance = value;
else
Console.WriteLine("Invalid balance");
Page 9 of 20
SHIVALIKCOLLEGEOFENGINEERING
RecognisedunderUGCSection(2f)oftheUGCAct1956
balance -= amount;
else
class Program
account.Deposit(100);
account.Withdraw(50);
Console.WriteLine($"Balance: {account.Balance}");
Output:
Balance: 50
Page 10 of 20
SHIVALIKCOLLEGEOFENGINEERING
RecognisedunderUGCSection(2f)oftheUGCAct1956
EXPERIMENT- 7
class ExceptionHandlingDemo
{
static void Main()
{
string filePath = "example.txt";
try
{
// Attempt to read the file
string content = File.ReadAllText(filePath);
Console.WriteLine("File Content:\n" + content);
}
catch (FileNotFoundException ex)
{
Console.WriteLine($"Error: The file '{filePath}' was not found.");
Console.WriteLine("Details: " + ex.Message);
}
catch (UnauthorizedAccessException ex)
{
Console.WriteLine($"Error: You don't have permission to access the file
'{filePath}'.");
Console.WriteLine("Details: " + ex.Message);
}
catch (Exception ex)
{
Console.WriteLine("An unexpected error occurred: " + ex.Message);
}
finally
{
Console.WriteLine("File reading operation is completed.");
}
}
}
Page 11 of 20
SHIVALIKCOLLEGEOFENGINEERING
RecognisedunderUGCSection(2f)oftheUGCAct1956
Output:
Page 12 of 20
SHIVALIKCOLLEGEOFENGINEERING
RecognisedunderUGCSection(2f)oftheUGCAct1956
EXPERIMENT- 8
public CalculatorForm()
{
// TextBox for Number 1
txtNumber1 = new TextBox { Location = new System.Drawing.Point(20, 20),
Width = 100 };
Controls.Add(txtNumber1);
// Buttons
btnAdd = new Button { Text = "Add", Location = new System.Drawing.Point(150,
20) };
btnAdd.Click += (sender, e) => PerformOperation("Add");
Controls.Add(btnAdd);
switch (operation)
{
case "Add":
result = num1 + num2;
break;
case "Subtract":
result = num1 - num2;
break;
case "Multiply":
result = num1 * num2;
break;
case "Divide":
if (num2 == 0) throw new DivideByZeroException("Cannot divide by
zero.");
result = num1 / num2;
break;
}
Page 14 of 20
SHIVALIKCOLLEGEOFENGINEERING
RecognisedunderUGCSection(2f)oftheUGCAct1956
[STAThread]
public static void Main()
{
Application.EnableVisualStyles();
Application.Run(new CalculatorForm());
}
}
Output:
1. Addition:
o Input: Number 1 = 10, Number 2 = 20
o Output: Result: 30
2. Division by Zero:
o Input: Number 1 = 10, Number 2 = 0
o Output: MessageBox: "Cannot divide by zero."
3. Invalid Input:
o Input: Number 1 = abc, Number 2 = 5
o Output: MessageBox: "Please enter valid numbers."
4. Other Operations:
o Subtraction: Result: -10
o Multiplication: Result: 200
o Division: Result: 2
Page 15 of 20
SHIVALIKCOLLEGEOFENGINEERING
RecognisedunderUGCSection(2f)oftheUGCAct1956
EXPERIMENT:9
using System.Data.SqlClient;
using System.Windows.Forms;
public MainForm()
InitializeComponent();
conn.Open();
Page 16 of 20
SHIVALIKCOLLEGEOFENGINEERING
RecognisedunderUGCSection(2f)oftheUGCAct1956
while (reader.Read())
Output:
Popup 1:
Popup 2:
Popup 3:
Page 17 of 20
SHIVALIKCOLLEGEOFENGINEERING
RecognisedunderUGCSection(2f)oftheUGCAct1956
EXPERIMENT-10
1. Deployment Steps:
Go to Build → Publish.
2. Installation:
Page 18 of 20
SHIVALIKCOLLEGEOFENGINEERING
RecognisedunderUGCSection(2f)oftheUGCAct1956
Installation Complete!
3. Execution:
Expected Behavior:
Output Example
Page 19 of 20
SHIVALIKCOLLEGEOFENGINEERING
RecognisedunderUGCSection(2f)oftheUGCAct1956
Result of 5 + 3 = 8
Student Records:
Page 20 of 20