0% found this document useful (0 votes)
10 views19 pages

C# and VB.NET Lab Practical Guide

BCA
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views19 pages

C# and VB.NET Lab Practical Guide

BCA
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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

Common questions

Powered by AI

The use of built-in functions in a VB.NET application enhances usability by offering pre-built functionalities, like Len for string length and StrReverse for reversing strings, reducing development time and potential errors. However, heavy reliance on these functions may obscure business logic, making the application less transparent and potentially hindering extensibility as specific application logic might become tightly coupled with built-in calls .

Radio buttons facilitate mutual exclusivity where only one option can be selected at a time, simplifying single-choice scenarios like mathematical operation selection. List boxes offer a scrollable list of options, such as color names, enabling efficient selection from many items. These controls enhance user interaction through intuitive design and ease of use, allowing users to make choices swiftly without needing to type or remember commands .

MDI, or Multiple Document Interface, allows a VB.NET application to manage multiple child windows within a single parent form. In the MDI Employee Payroll application, Form1 acts as the MDI container (IsMdiContainer set to True), enabling multiple Form2 instances for employee details management. This design supports better organization and navigation between related windows within the parent window .

Though the specific details of implementing database connectivity in C#.NET for core-banking transactions are not fully provided in the sources, typically this involves using ADO.NET to establish a connection to the database. The application would utilize SqlConnection objects to connect, SqlCommand to execute queries, and SqlDataReader or DataSet to retrieve and manipulate data. The application likely involves mapping these interactions to user interface operations to handle core banking functionalities such as transactions .

Multithreading in the C#.NET application is implemented using the Thread class. Two threads, t1 and t2, are created to execute separate methods, Table7 and Table3, which print multiplication tables with delays. This allows concurrent execution, optimizing CPU usage and preventing the main thread from being blocked. Each thread independently prints numbers at intervals, demonstrating asynchronous processing .

The student class in the C#.NET application illustrates several OOP concepts, including encapsulation through private data members (roll, name, m1, m2, m3, tot, avg), constructors for initializing objects, and polymorphism through method overloading, evidenced by two versions of the marks() method—one without arguments and one with three integer parameters. Additionally, the class demonstrates abstraction by offering high-level operations like calculating total and average marks and output functions .

The C# .NET console application first prompts the user to input two numbers. It then uses if-else conditional logic to compare the numbers. If both numbers are equal, the program outputs 'Both {a} and {b} are Equal', indicating that neither is greater .

Control statements in C# .NET like 'for' and 'while' loops manage iteration, allowing repetitive execution of a block of code. For instance, a 'for' loop iterates from 0 to 20, printing each number sequentially. The 'while' loop example iterates, printing even numbers up to 50. Decision-making is shown using 'if-else' and 'switch' statements, controlling execution flow based on conditions, such as checking user-input numeric values to determine outputs .

In the VB.NET web application, dynamic login processing involves checking user input against hardcoded credentials ('MSCW' and 'BCA') and providing immediate feedback through message boxes for success or failure. While functional, security can be enhanced by using hashed passwords and secure storage, rather than hardcoding sensitive data, to prevent unauthorized access and enhance security against attacks .

Conditional statements, like if-else, offer more flexibility for complex logic evaluation, allowing checks for ranges and combinations of conditions, as used to determine which input number is greater. Switch statements provide a cleaner, better-structured approach for handling distinct cases of a single variable, such as choosing colors based on user input, but are limited to single-variable evaluation and distinct, non-overlapping conditions, which are less versatile than conditional blocks .

You might also like