BCA - III Semester - C# and .
Net Technologies Lab
Practicals:
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. Demonstrate Multithreaded Programming in C#.NET
4. Demonstrate subroutines and functions in C#.NET
5. Construct a console application to demonstrate the OOP Concepts
--------
6. Develop an application in C#.NET that demonstrates the windows controls
7. Develop a web application in [Link] for dynamic Login Processing
8. Develop an application for deploying various built-in functions in [Link]
9. Develop an MDI application for Employee Pay-roll transactions in [Link]
10. Develop a Windows application with database connectivity for core-banking
transactions
[Link] C K, Asst. Prof., MSCW, Mysore. 1
1. Develop a C# .NET console application to demonstrate the conditional
statements.
// 1.a. Program using if else
using System;
class ifdemo
{
public static void Main()
{
int a,b;
[Link]("enter 2 no ");
a=[Link] ([Link]());
b=[Link]([Link]());
if(a>b)
{
[Link](a+" is greater");
}
else if(a< b)
{
[Link](b+" is greater");
}
else
{
[Link]("Both "+a+" and "+b+" are Equal");
}
[Link]();
}
}
// 1.b. Program using switch
using System;
namespace ConditionalStatementDemo
{
class Switchdemo
{
public static void Main()
{
[Link]("Which is your fav. color");
[Link]("1. Red");
[Link] C K, Asst. Prof., MSCW, Mysore. 2
[Link]("2. Green");
[Link]("3. Pink");
int ch = [Link]([Link]());
switch (ch)
{
case 1:
[Link]("you choose Red");
break;
case 2 :
[Link]("you choose Green");
break;
case 3:
[Link]("you choose Pink");
break;
default:
[Link]("None of given colors..");
break;
}
[Link]();
}
}
}
Output:
Which is your fav. color
1. Red
2. Green
3. Pink
8
None of given colors..
Which is your fav. color
1. Red
2. Green
3. Pink
2
you choose Green
[Link] C K, Asst. Prof., MSCW, Mysore. 3
2. Develop a C# .NET console application to demonstrate the control
statements.
// 2.a. Program using for loop
using System;
namespace ConditionalStatementDemo
{
class ForLoop
{
public static void Main()
{
[Link]("Printing first 20 numbers using For");
for (int i = 0; i <= 20; i++)
{
[Link](i);
}
[Link]();
}
}
}
Output:
Printing first 20 numbers using For
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[Link] C K, Asst. Prof., MSCW, Mysore. 4
17
18
19
20
// 2.b. program using while loop
using System;
namespace ConditionalStatementDemo
{
class WhileDemo
{
public static void Main()
{
int x=0;
[Link]("Printing Even nos. less than 50 using while: ");
while (x <= 50)
{
[Link](x);
x=x+2;
}
}
}
}
3. Demonstrate Multithreaded Programming in C#.NET
// 3. Multithreading
using System;
using [Link];
namespace ThreadingDemo
{
class Program1
{
public static void Main()
{
[Link]("Starting Main Thread");
Thread t1 = new Thread(Table7)
{
Name = "Table-7"
[Link] C K, Asst. Prof., MSCW, Mysore. 5
};
Thread t2 = new Thread(Table3)
{
Name = "Table-3"
};
[Link]();
[Link]();
[Link]("Exiting Main Thread");
[Link]();
}
static void Table7()
{
[Link]("Starting " + [Link]);
for (int i = 1; i <= 5; i++)
{
[Link]("7 * " + i + " = " + 7 * i);
[Link](2000);
}
[Link]("Exiting " + [Link]);
}
static void Table3()
{
[Link]("Staring " + [Link]);
for (int i = 1; i <= 5; i++)
{
[Link]("3 * " + i + " = " + 3 * i);
[Link](3000);
}
[Link]("Exiting " + [Link]);
}
}
}
[Link] C K, Asst. Prof., MSCW, Mysore. 6
4. Demonstrate subroutines and functions in C#.NET.
// 4. Subroutine and functions
using System;
namespace ConsoleApplication2
{
class Subroutine
{
public static void Main()
{
[Link]("Arithmetic Operations:");
[Link]("Enter two numbers:");
int a = [Link]([Link]());
int b = [Link]([Link]());
[Link]("1. Add");
[Link]("2. Sub");
[Link]("Enter Your Choice: ");
int ch = [Link]([Link]());
if (ch != 1 && ch != 2)
{
[Link]("Wrong Choice!!");
}
else if (ch == 1)
{
add(a, b);
}
else
{
int result = sub(a, b);
[Link]("Subtraction=" + result);
}
[Link]();
}
static void add(int n, int m)
{
[Link]("Addition=" + (n + m));
}
static int sub(int n, int m)
[Link] C K, Asst. Prof., MSCW, Mysore. 7
{
return (n - m);
}
}
5. Construct a console application to demonstrate the OOP Concepts
// 5. Oops concepts – class, object, polymorphism
using System;
namespace ConsoleApplication1
{
class student
{
int roll;
String name;
int m1, m2, m3;
int tot;
float avg;
student(int r,String n) //constructor
{
roll=r;
name=n;
}
void marks() //Polymorphism
{
m1 = 90; m2 = 95; m3 = 80;
}
void marks(int a,int b,int c) //Polymorphism
{
m1 = a; m2 = b; m3 = c;
}
void cal()
{
tot = m1 + m2 + m3;
avg = tot / 3;
}
void put()
[Link] C K, Asst. Prof., MSCW, Mysore. 8
{
[Link]("Student Roll: " + roll);
[Link]("Student Name: " + name);
[Link]("Total: " + tot);
[Link]("Percentage: " + avg);
}
public static void Main()
{
student s1 = new student(10, "Anu");
student s2 = new student(12, "Rakesh");
[Link]();
[Link](50, 60, 70);
[Link]();
[Link]();
[Link]("Student details:");
[Link]();
[Link]();
[Link]();
[Link]();
}
}
}
6. Develop an application in C#.NET that demonstrates the windows controls.
Select New Project-> Visual C# -> Windows Forms Application.
Use Toolbox and Properties window.
Create the design in the form.
[Link] C K, Asst. Prof., MSCW, Mysore. 9
Design of [Link]
NOTE:
● For textBox3 -> In Properties window -> ReadOnly is set to True.
● For ListBox2 -> In Properties window -> in the Items property -> the
different colour names are entered.
C# code:
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
[Link] = [Link]([Link]) + [Link]([Link])+"";
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
[Link] C K, Asst. Prof., MSCW, Mysore. 10
[Link] = [Link]([Link]) - [Link]([Link])+"";
}
private void button1_Click(object sender, EventArgs e)
{
switch([Link])
{
case 0:
[Link] = [Link];
break;
case 1:
[Link]=[Link];
break;
case 2:
[Link]=[Link];
break;
case 3:
[Link]=[Link];
break;
}
}
7. Develop a web application in [Link] for dynamic Login Processing
Select New Project-> Under Installed Templates-> Visual Basic -> Windows
Forms Application.
Use Toolbox and Properties window.
Create the design in the form.
[Link] C K, Asst. Prof., MSCW, Mysore. 11
Design of [Link]:
NOTE:
● For textBox2 -> In Properties window -> PasswordChar is set to *.
VB code:
Public Class Form1
Private Sub Button1_Click( ) Handles [Link]
If [Link] = "" Then
MsgBox("Enter Username.." , , "Login Screen")
[Link]()
ElseIf [Link] = "" Then
MsgBox("Enter Password.." , , "Login Screen")
[Link]()
ElseIf [Link] = "MSCW" And [Link] = "BCA" Then
MsgBox("Login Success!!" , , "Login Screen")
[Link] C K, Asst. Prof., MSCW, Mysore. 12
Else
MsgBox("Incorrect Username/Password. Try Again!!" , , "Login
Screen")
End If
End Sub
Private Sub Button2_Click() Handles [Link]
[Link] = ""
[Link] = ""
[Link]()
End Sub
End Class
8. Develop an application for deploying various built-in functions in [Link]
Select New Project-> Under Installed Templates-> Visual Basic -> Windows
Forms Application.
Use Toolbox and Properties window.
Create the design in the form.
Design of [Link]:
[Link] C K, Asst. Prof., MSCW, Mysore. 13
NOTE:
· To create shortcut key for Button1, In Properties window -> Text is
entered as &Length
o So now L is the shortcut key. During execution, instead of
button click, Alt+L is pressed.
· Similarly shortcuts are assigned for all the remaining Buttons.
VB code:
Public Class Form1
Private Sub Button1_Click() Handles [Link]
MsgBox(Len([Link]))
End Sub
Private Sub Button2_Click() Handles [Link]
MsgBox(StrReverse([Link]), , "String Reverse")
End Sub
[Link] C K, Asst. Prof., MSCW, Mysore. 14
Private Sub Button3_Click() Handles [Link]
Dim str As String
str = InputBox("Enter a string to compare:", "String Comparison")
If StrComp([Link], str) = 0 Then
MsgBox("Both are Equal", , "String Comparison")
Else
MsgBox("Not Equal Strings", , "String Comparison")
End If
End Sub
Private Sub Button4_Click() Handles [Link]
[Link] = Trim([Link])
End Sub
Private Sub Button5_Click() Handles [Link]
[Link] = UCase([Link])
End Sub
Private Sub Button6_Click() Handles [Link]
[Link] = LCase([Link])
End Sub
Private Sub Button7_Click() Handles [Link]
Dim c As Char
c = InputBox("Enter the character to replace:", "Replace")
[Link] = Replace([Link], c, "#")
End Sub
Private Sub Button8_Click( ) Handles [Link]
Close()
End Sub
End Class
9. Develop an MDI application for Employee Pay-roll transactions in [Link]
[Link] C K, Asst. Prof., MSCW, Mysore. 15
Select New Project-> Under Installed Templates-> Visual Basic -> Windows
Forms Application.
Use Toolbox and Properties window.
Create the design in the form.
Design of [Link]:
NOTE:
● In Form1 - IsMdiContainer is set to True.
Design of [Link]:
[Link] C K, Asst. Prof., MSCW, Mysore. 16
VB Code in Form1:
Public Class Form1
Public empname As String
Public desig As String
Public basic As Decimal
Public grosssal As Decimal
Public netsal As Decimal
Private Sub Button1_Click() Handles [Link]
[Link] = Me
empname = [Link]
desig = [Link]
basic = Int([Link])
grosssal = basic + (basic * 0.34) + (basic * 0.16)
netsal = grosssal - (Int([Link]) + Int([Link]))
[Link]()
End Sub
[Link] C K, Asst. Prof., MSCW, Mysore. 17
Private Sub Button3_Click() Handles [Link]
[Link]()
End Sub
End Class
VB Code in Form2:
Public Class Form2
Private Sub Form2_Load() Handles [Link]
[Link] = [Link]("MMMM")
[Link] = [Link]
[Link] = [Link]
[Link] = Str([Link])
[Link] = Str([Link])
End Sub
End Class
Output Screen:
[Link] C K, Asst. Prof., MSCW, Mysore. 18
[Link] C K, Asst. Prof., MSCW, Mysore. 19