Final Net Practical File
Final Net Practical File
Lab Record
Submitted to Submitted by
Mr. Girish Bisht Akash Giri
Assistant professor 200120101012
EXPERIMENT-1
PROGRAM
Using System;
class Person
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
}
class Program
{
static void Main(string[] args)
{
Person obj1 = new Person();
obj1.Name = "Aakash";
Console.WriteLine(obj.Name);
}
}
OUTPUT:
Aakash
PROGRAM
using System;
public class ArmstrongExample
{
public static void Main(string[] args)
{
int n,r,sum=0,temp;
Console.Write("Enter the Number= ");
n = int.Parse(Console.ReadLine());
temp=n;
while(n>0)
{
r=n%10;
sum=sum+(r*r*r);
n=n/10;
}
if(temp==sum)
Console.Write("Armstrong Number.");
else
Console.Write("Not Armstrong Number.");
}
}
OUTPUT:
EXPERIMENT-4
Aim: Create a console application to calculate area of circle. Accept radius from user
and print it.Create and console application to build simple calculator, calculator will
have following functions Accept 2 numbers perform Add/Sub/Multi and print result.
using System;
class Circle{
static void Main(string[] args){
Console.Write("Enter Radius: ");
double rad = Convert.ToDouble(Console.ReadLine());
double area = Math.PI * rad * rad;
Console.WriteLine("Area of circle is: " + area);
}
}
OUTPUT:
class Program
{
static void Main(string[] args){
int num1;
int num2;
string operand;
ConsoleKeyInfo status;
float answer;
while (true)
{
Console.Write("Please enter the first integer: ");
num1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Please enter the second integer: ");
num2 = Convert.ToInt32(Console.ReadLine());
Console.Write("Please enter an operand (+, -, /, *): ");
operand = Console.ReadLine();
switch (operand)
{
case "-":
answer = num1 - num2;
break;
case "+":
answer = num1 + num2;
break;
case "/":
answer = num1 / num2;
break;
case "*":
answer = num1 * num2;
break;
default:
answer = 0;
break;
}
Console.WriteLine(num1.ToString() + " " + operand + " " + num2.ToString() + " = "
+
answer.ToString());
Console.WriteLine("\n\n Do You Want To Break (Y/y)");
status = Console.ReadKey();
if(status.Key==ConsoleKey.Y)
{
break;
}
Console.Clear();
}
}
}
OUTPUT:
EXPERIMENT-5
PROGRAM
using System;
public class InvalidAgeException : Exception{
public InvalidAgeException(String message)
: base(message)
{
}
}
public class TestUserDefinedException{
static void validate(int age){
if (age < 18){
throw new InvalidAgeException("Sorry, Age must be greater than 18");
}
}
public static void Main(string[] args){
try {
Validate(19);
validate(12);
}
catch (InvalidAgeException e) { Console.WriteLine(e); }
}
}
OUTPUT
EXPERIMENT-6
Aim: Write a program to implement the concept of Abstract and Sealed classes.
PROGRAM
using System;
public abstract class Animal
{
public abstract string Sound { get; }
public virtual void Move()
{
Console.WriteLine("Moving...");
}
}
class Program
{
static void Main(string[] args)
{
Animal[] animals = new Animal[] { new Cat(), new Dog() };
foreach (Animal animal in animals)
{
Console.WriteLine($"The {animal.GetType().Name} goes {animal.Sound}");
animal.Move();
}
}
}
OUTPUT :
PROGRAM
using System;
sealed class SealedClass {
public int Add(int a, int b){
return a + b;
}
}
class Program {
static void Main(string[] args){
SealedClass slc = new SealedClass();
int total = slc.Add(6, 4);
Console.WriteLine("Total = " + total.ToString());
}
}
OUTPUT:
EXPERIMENT-7
PROGRAM
using System;
using System.Data.SqlClient;
namespace AdoNetConsoleApplication
{
class Program{
static void Main(string[] args)
{
new Program().Connecting();
}
public void Connecting()
{
using (
SqlConnection con = new SqlConnection(“datasource=.;
database=student; integrated security=SSPI”)
)
{
con.Open();
Console.WriteLine("Connection Established Successfully");
}
}
}
}
OUTPUT:
EXPERIMENT-8
PROGRAM
using System;
using System.IO;
public sealed class Program{
public static void Main(){
using (Stream s = new FileStream(@"c:\A\file.txt", FileMode.Open))
{
int obj;
while ((obj = s.ReadByte()) != -1)
{
Console.Write("{0} ", (char)obj);
}
Console.ReadLine();
}
}
}
EXPERIMENT-9
Implementation of Events:
PROGRAM
using System;
namespace SampleApp {
public delegate string MyDel(string str);
class EventProgram {
event MyDel MyEvent;
public EventProgram() {
this.MyEvent += new MyDel(this.WelcomeUser);
}
public string WelcomeUser(string username) {
return "Welcome " + username;
}
static void Main(string[] args) {
EventProgram obj1 = new EventProgram();
string result = obj1.MyEvent("This is event 1");
Console.WriteLine(result);
}
}
}
OUTPUT:
Implementation of Delegates:
PROGRAM
using System;
class Program{
public delegate void addnum(int a, int b);
public delegate void subnum(int a, int b);
//Add method
public void sum(int a, int b){
Console.WriteLine("(100 + 40) = {0}", a + b);
}
// subtract method
public void subtract(int a, int b){
Console.WriteLine("(100 - 60) = {0}", a - b);
}
del_obj1(100, 40);
del_obj2(100, 60);
}
}
OUTPUT:
EXPERIMENT-11
PROGRAM
using System;
public class MyCollection{
private int[] data = new int[10];
public int this[int index, bool square]{
get
{
if (square)
return data[index] * data[index];
else
return data[index];
}
set
{
if (square)
data[index] = (int)Math.Sqrt(value);
else
data[index] = value;
}
}
default:
throw new ArgumentException("Invalid index parameter.");
}
}
}
// Read-only indexer
public int this[int index]
{
get { return data[index]; }
}
}
Console.WriteLine(collection[0, false]);
Console.WriteLine(collection[1, true]);
Console.WriteLine(collection["first"]);
Console.WriteLine(collection["last"]);
// Getting values using read-only indexer
Console.WriteLine(collection[2]);
Console.ReadLine();
}
}
OUTPUT:
EXPERIMENT-2
PROGRAM
using System;
class Program {
static void Main(string[] args) {
int[] numbers = {1,2,3,4,5,6,7,8};
Console.WriteLine("Element in first index : " + numbers[0]);
Console.WriteLine("Element in second index : " + numbers[1]);
Console.WriteLine("Element in third index : " + numbers[2]);
Console.WriteLine("Element in fourth index : " + numbers[3]);
Console.WriteLine("Element in five index : " + numbers[4]);
Console.ReadLine();
}
}
OUTPUT:
EXPERIMENT-10
Aim: Design the WEB base Database connectivity Form by using ASP. NET.
PROGRAM:
<!DOCTYPE html>
<html>
<head>
<title>Database Connectivity Form</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Database Connectivity Form</h2>
<label for="txtName">Name:</label>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox><br /><br />
<label for="txtEmail">Email:</label>
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox><br /><br />
using System;
using System.Configuration;
using System.Data.SqlClient;
namespace YourNamespace
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// You can add code here that executes when the page loads
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
// Retrieve form data
string name = txtName.Text;
string email = txtEmail.Text;
try
{
connection.Open();
int rowsAffected = command.ExecuteNonQuery();
if (rowsAffected > 0)
{
Response.Write("Data inserted successfully!");
}
}
catch (Exception ex)
{
Response.Write("Error: " + ex.Message);
}
}
}
}
}
Table of Contents