C# AND .
NET FRAMEWORK
[Link] NAME OF PROGRAMS
1 Develop a C# .NET console application to demonstrate the
conditional statements.
2 Develop a C#.NET console application to demonstrate the
control statements.
3 Develop an application in C#.NET and demonstrates the
windows controls.
4 Demonstrate Multithreaded Programming in C#.NET.
5 Demonstrate subroutines and functions in C#.NET.
6 Develop an application for deploying various built-in
functions in [Link]
7 Develop an MDI application for Employee Pay-roll
transactions in [Link].
8 Construct a console application to demonstrate the OOP
Concepts
9 Develop a web application in [Link] for dynamic Login
Processing.
10 Develop a Windows application with database connectivity
for core banking transactions.
C# and .Net framework lab programs
1. Develop a C#.NET console application to demonstrate the conditional statements.
using System;
using [Link];
using [Link];
using [Link];
using [Link];
namespace Conditional3
{
class Program
{
static void Main(string[] args)
{
int i = 1;
[Link]("1 to 10 Numbers");
while(i<=10)
{
[Link](i);
i++;
}
[Link]();
}
}
}
********************OUTPUT********************
DEPT. OF COMPUTER APPLICATION Vidya Modi[Lecture]
C# and .Net framework lab programs
2. Develop a C#.NET console application to demonstrate the control statements.
using System;
class Test
{
static public void Main()
{
string x = "Shree medha Degree";
string y = "BCA";
if (x == y)
{
[Link]("Both strings are equal..!!");
}
else
{
[Link]("Both strings are not equal..!!");
}
[Link]();
}
}
********************OUTPUT********************
DEPT. OF COMPUTER APPLICATION Vidya Modi[Lecture]
C# and .Net framework lab programs
3. Develop an application in C#.NET and demonstrates the windows controls.
using System;
using [Link];
namespace WindowsControls
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
String name, course, year, gender=" ", hobbies=" ";
String date;
name = [Link];
date = [Link]([Link]);
course = [Link];
if ([Link] == true)
gender = [Link];
else if ([Link] == true)
gender = [Link];
if ([Link] == true)
hobbies = [Link];
if ([Link] == true)
hobbies =hobbies +" "+ [Link];
[Link]("Name : " + name + "\nDOB : " + date + "\nGender : " + gender +
"\nCourse : " + course + "\nHobbies : " + hobbies);
}
private void button2_Click(object sender, EventArgs e)
{
Close();
}
}
}
DEPT. OF COMPUTER APPLICATION Vidya Modi[Lecture]
C# and .Net framework lab programs
********************OUTPUT********************
DEPT. OF COMPUTER APPLICATION Vidya Modi[Lecture]
C# and .Net framework lab programs
4. Demonstrate Multithreaded Programming in C#.NET.
using System;
using [Link];
public class AOne
{
public void First()
{
[Link]("First method of AOne class is running on T1 thread.");
[Link](1000);
[Link]("The First method called by T1 thread has ended.");
}
public static void Second()
{
[Link]("Second method of AOne class is running on T2 thread.");
[Link](2000);
[Link]("The Second method called by T2 thread has ended.");
}
}
public class ThreadExp
{
public static int Main(String[] args)
{
[Link]("Example of Threading");
AOne a = new AOne();
Thread T1 = new Thread(new ThreadStart([Link]));
[Link]();
[Link]("T1 thread strated.");
Thread T2 = new Thread(new ThreadStart([Link]));
[Link]();
[Link]("T2 thread started.");
[Link]();
return 0;
}
}
********************OUTPUT********************
DEPT. OF COMPUTER APPLICATION Vidya Modi[Lecture]
C# and .Net framework lab programs
5. Demonstrate subroutines and functions in C#.NET.
using System;
class Program
{
public void Function(int x, int y)
{
int res = x + y;
[Link]("Sum of two Values=" + res);
}
public int Subroutine(int x, int y)
{
return x + y;
}
class test
{
static void Main(string[] args)
{
Program p = new Program();
int x = 18, y = 20;
[Link]("Demonstration of function and Subroutine using C#");
[Link](x, y);
[Link](x, y);
[Link]();
}
}
}
********************OUTPUT********************
DEPT. OF COMPUTER APPLICATION Vidya Modi[Lecture]
C# and .Net framework lab programs
6. Develop an application for deploying various built-in functions in [Link].
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles [Link]
[Link] = Len([Link])
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles [Link]
[Link] = StrReverse([Link])
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles [Link]
[Link] = UCase([Link])
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles [Link]
[Link] = LCase([Link])
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles [Link]
[Link] = Trim([Link])
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles [Link]
Dim n1, n2 As Integer
n1 = Val([Link])
n2 = Val([Link])
[Link] = [Link](n1, n2)
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles [Link]
Dim n1, n2 As Integer
n1 = Val([Link])
n2 = Val([Link])
[Link] = [Link](n1, n2)
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles [Link]
Dim n1 As Integer
n1 = Val([Link])
[Link] = [Link](n1)
End Sub
Private Sub Button9_Click(sender As Object, e As EventArgs) Handles [Link]
[Link] = [Link]([Link])
DEPT. OF COMPUTER APPLICATION Vidya Modi[Lecture]
C# and .Net framework lab programs
End Sub
Private Sub Button10_Click(sender As Object, e As EventArgs) Handles [Link]
[Link]()
[Link]()
[Link]()
End Sub
End Class
********************OUTPUT********************
DEPT. OF COMPUTER APPLICATION Vidya Modi[Lecture]
C# and .Net framework lab programs
7. Develop an MDI application for Employee Pay-roll transactions in [Link].
Form_1.vb :
Public Class Form1
Private Sub CreateSalaryToolStripMenuItem_Click(sender As Object, e As EventArgs)
Handles [Link]
Hide()
Dim sf As Form2 = New Form2()
[Link]()
[Link] = "Create Salary"
End Sub
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs)
Handles [Link]
[Link]()
End Sub
End Class
[Link] :
Public Class Form2
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles [Link]
Dim eid As String = [Link]
Dim ename As String = [Link]
Dim basic As Integer = Convert.ToInt32([Link])
Dim ta As Integer = Convert.ToInt32([Link])
Dim da As Integer = Convert.ToInt32([Link])
Dim pt As Integer = Convert.ToInt32([Link])
Dim gross As Integer
gross = basic + ta + da
Dim net As Integer
DEPT. OF COMPUTER APPLICATION Vidya Modi[Lecture]
C# and .Net framework lab programs
net = gross - pt
MsgBox([Link]("Eid:{0} Ename:{1} Gross:{2} Net:{3}", eid, ename, gross,
net))
End Sub
End Class
DEPT. OF COMPUTER APPLICATION Vidya Modi[Lecture]
C# and .Net framework lab programs
********************OUTPUT********************
DEPT. OF COMPUTER APPLICATION Vidya Modi[Lecture]
C# and .Net framework lab programs
8. Construct a console application to demonstrate the OOP’S concepts.
using System;
public class Student
{
String name;
String course;
int age;
String address;
public Student(String name, String course,
int age, String address)
{
[Link] = name;
[Link] = course;
[Link] = age;
[Link] = address;
}
public String GetName()
{
return name;
}
public String GetCourse()
{
return course;
}
public int GetAge()
{
return age;
}
public String GetAddress()
{
return address;
}
public String ToString()
{
return ("Hi my name is " + [Link]()+ ".\nMy course, age and address are " +
[Link]()+ ", " + [Link]() + ", " + [Link]());
}
DEPT. OF COMPUTER APPLICATION Vidya Modi[Lecture]
C# and .Net framework lab programs
public static void Main(String[] args)
{
Student s = new Student("Giriraj", "BCA", 20, "Ballari");
[Link]([Link]());
[Link]();
}
}
********************OUTPUT********************
DEPT. OF COMPUTER APPLICATION Vidya Modi[Lecture]
C# and .Net framework lab programs
9. Develop a web application in [Link] for dynamic Login Processing.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles [Link]
Dim uname As String
Dim pwd As String
uname = [Link]
pwd = [Link]
If (uname = "Student" And pwd = "1234") Then
MsgBox("Login Successful!..")
Else
MsgBox("Login Failed!.." & vbCrLf & "Incorrect Username or Password!..")
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles [Link]
[Link]()
End Sub
End Class
DEPT. OF COMPUTER APPLICATION Vidya Modi[Lecture]
C# and .Net framework lab programs
********************OUTPUT********************
DEPT. OF COMPUTER APPLICATION Vidya Modi[Lecture]
C# and .Net framework lab programs
10. Develop a Windows application with database connectivity for core banking
transactions
Design table in Sqlserver Object Explorer
Goto -> Sql Server Object Explorer
> Create database Csharp Lab
DEPT. OF COMPUTER APPLICATION Vidya Modi[Lecture]
C# and .Net framework lab programs
> Add table bank with fields
(Name(varchar),AccNo(varchar),AccType(Varchar),Amount
(int) ,Pin(int))
Connection String:
Rightclick on Csharp Database > Properties > Find connection String
Copy Connection String paste in [Link] Code.
Connection string changing depending on your database and location.
DEPT. OF COMPUTER APPLICATION Vidya Modi[Lecture]
C# and .Net framework lab programs
Step1:
File> New> Project
Select Visual Basic Left side Panel and Right Side Windows Forms App
Step2:
Add 4 Buttons from tools Change ‘Text ‘ Properties Buttons as per design.
Double click on Create Button , Deposit Button, Withdraw Button,
Balance ButtonCode :
DEPT. OF COMPUTER APPLICATION Vidya Modi[Lecture]
C# and .Net framework lab programs
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles [Link]
Dim createfrm As New Create
[Link]()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles [Link]
Dim depositfrm As New Deposit
[Link]()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles [Link]
Dim withdrawfrm As New Withdraw
[Link]()
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles [Link]
Dim balancefrm As New Balance
[Link]()
End Sub
End Class
Step3:
In Solution Explorer Select Project Bank Right Click >Add New Windows Forms 4
times > Named Create, Deposit,Withdraw,Balance
DEPT. OF COMPUTER APPLICATION Vidya Modi[Lecture]
C# and .Net framework lab programs
Change Name Properties of Textboxes to -> txtName , txtAccNo, txtAccType,
txtAmount, txtPin Label Text properties to Name, Account Number,Account Type,
Amount, Pin as per requirement Button Text Property to Create
Double click on Create
Write Code:
Imports
[Link]
Public Class Create
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles [Link]
Dim constring As String = "Data Source=(localdb)\MSSQLLocalDB;Initial
Catalog=Csharplab;Integrated Security=True;Connect
Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=Read
Write;MultiSubnetFailover=False"
Dim con As New SqlConnection() [Link] =
constring
Dim qry As String = "Insert into [dbo].Bank values('" + [Link] + "','" +
[Link] + "','" + [Link] + "'," + [Link] + "," + [Link] + ")"
[Link]()
Dim cmd As New SqlCommand(qry, con)
Dim res As Integer
res=[Link]()
If res = 1 Then
MsgBox("Account created successfully!")
End If
[Link]()
End Sub
DEPT. OF COMPUTER APPLICATION Vidya Modi[Lecture]
C# and .Net framework lab programs
End Class
Design Deposit Form as shown Above
Change textbox properties and Label properties
Textbox1(name)- txtAccNo
Textbox2 (name)- txtAmount
Button (Text) – Deposit
Write Code:
Imports [Link]
Public Class Deposit
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles [Link]
Dim constring As String = "Data Source=(localdb)\MSSQLLocalDB;Initial
Catalog=Csharplab;Integrated Security=True;Connect
Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;
MultiSubnetFailover=False"
Dim con As New SqlConnection() [Link] =constring
Dim qry As String = "Update [dbo].bank set amount=amount+" + [Link] +"
where Accno='" + [Link] + "'"
[Link]()
Dim cmd As New SqlCommand(qry, con)
Dim res As Integer
res = [Link]()
DEPT. OF COMPUTER APPLICATION Vidya Modi[Lecture]
C# and .Net framework lab programs
If res = 1 Then
MsgBox("Amount Deposited successfully!")
End If
[Link]()
End Sub
End Class
Design Withdraw form as specified above Change Textbox Properties and Label
Properties
Textbox Name properties : txtAccNo, txtAmount,txtPin
Label Text Properties: Account Number, Amount, Pin
Button Text Property: Withdraw
Double click on Withdraw button
Write Code in button click event:
Imports [Link]
Public Class Withdraw
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles [Link] Dim
constring As String = "Data Source=(localdb)\MSSQLLocalDB;Initial
Catalog=Csharplab;Integrated Security=True;Connect
DEPT. OF COMPUTER APPLICATION Vidya Modi[Lecture]
C# and .Net framework lab programs
Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;
Mult iSubnetFailover=False"
Dim con As New SqlConnection() [Link] = constring
Dim qry As String = "Update [dbo].bank set amount=amount-" + [Link] + "
where Accno='" + [Link] + "' and Pin=" + [Link] + ""
[Link]()
Dim cmd As New SqlCommand(qry, con)
Dim res As Integer
res = [Link]() If res = 1 Then
MsgBox("Amount Withdrwan successfully!")
End If
[Link]()
End Sub
End Class
Balance Form Design Accordingly:
Change textbox and label Properties accordingly:
TextBox name properties: txtAccNo, txtPin
Labels Text properties: Account Number, Pin
Button text : Balance
DEPT. OF COMPUTER APPLICATION Vidya Modi[Lecture]
C# and .Net framework lab programs
Doubleclick on Button
Write Code:
Imports [Link]
Public Class Balance
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles [Link] Dim
constring As String = "Data Source=(localdb)\MSSQLLocalDB;Initial
Catalog=Csharplab;Integrated Security=True;Connect
Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;
Mult iSubnetFailover=False"
Dim con As New SqlConnection() [Link] = constring
Dim qry As String = "Select amount from [dbo].bank where Accno='" + [Link] +
"' and Pin=" + [Link] + ""
[Link]()
Dim cmd As New SqlCommand(qry, con)
Dim balance As Object balance = [Link]()
MsgBox("Available Balance=" + [Link]()) [Link]()
End Sub
End Class
DEPT. OF COMPUTER APPLICATION Vidya Modi[Lecture]