You are on page 1of 93

EX NO: 01

Write a program
Console to develop
application a control application
to demonstrate
to demonstrate the control structure in c#.
DATE: 07.02.2022 the control structures in C#

Aim

To write programs to demonstrate control structures in C#.

Algorithm

 Open the Visual Studio.


 Click on New project → Visual C# →Console Application.
 Implement the coding for various control statements such as If, If Else, If Else ladder,
Do, Do While, For loop.
 Save and run the application go get the output .
Program coding

If

using System;
using System.Collections.Generic;
using System.Text;
namespace @if
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a number");
int num = Convert.ToInt32(Console.ReadLine());
if (num % 2 == 0)
{
Console.WriteLine("It is even number");
}
Console.WriteLine("Press Enter key to Exit...");
Console.ReadLine();
}
}
}
Output

Enter a number

18

It is even number

Press Enter key to Exit...


If Else

using System;
using System.Collections.Generic;
using System.Text;
namespace ifelse
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a number");
int num = Convert.ToInt32(Console.ReadLine());
if (num % 2 == 0)
{
Console.WriteLine("It is even number");
}
else
{
Console.WriteLine("It is odd number");
}
Console.WriteLine("Press Enter key to Exit...");
Console.ReadLine();
}
}
}
Output

Enter a number

59

It is odd number

Press Enter key to Exit...


Else if ladder

using System;
using System.Collections.Generic;
using System.Text;
namespace elseif
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a number");
int number = Convert.ToInt32(Console.ReadLine());
if (number < 0 || number > 100)
{
Console.WriteLine("Wrong Number");
}
else if (number >= 10 && number < 0)
{
Console.WriteLine("Fail");
}
else if (number >= 50 && number < 60)
{
Console.WriteLine("D Grade");
}
else if (number >= 60 && number < 70)
{
Console.WriteLine("C Grade");
}
else if (number >= 70 && number < 80)
{
Console.WriteLine("B Grade");
}
else if (number >= 80 && number < 90)
{
Console.WriteLine("A Grade");
}
else if (number >= 90 && number < 100)
{
Console.WriteLine("A+ Grade");
}
Console.WriteLine("Press Enter key to Exit...");
Console.ReadLine();
}
}
}
Output

Enter a number

98

A+ Grade

Press Enter key to Exit...


For Loop

using System;
using System.Collections.Generic;
using System.Text;

namespace For
{
class Program
{
static void Main(string[] args)
{
int a = 5, sum = 0;
for(int i=1;i<=a; i++)
{
//sum=sum+i;
sum+=i;
}
Console.WriteLine("Sum of the first {0} natural numbers={1}",a,sum);
Console.ReadKey();
}
}
}
Output

Sum of the first 5 natural numbers=15


Do While

using System;
using System.Collections.Generic;
using System.Text;

namespace dowhile
{
class Program
{
static void Main(string[] args)
{
int i = 1, n = 5, product;
Console.WriteLine("The product of n and i are:");
Console.WriteLine("---------------------------");
do
{
product = n * i;
Console.WriteLine("{0} * {1} = {2}", n, i, product);
i++;
}
while (i <= 10);
Console.ReadKey();
}
}
}
Output
The product of n and i are:
---------------------------
5*1=5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
For Each

using System;
using System.Collections.Generic;
namespace Loop
{
class ForEachLoop
{
public static void Main(string[] args)
{
var numbers = new List<int>() { 5, -8, 3, 14, 9, 17, 0, 4 };
int sum = 0;
foreach (int number in numbers)
{
sum += number;
}
Console.WriteLine("The sum of numbers in the Array are:");
Console.WriteLine("Sum = {0}", sum);
Console.ReadLine();
}
}
}
Output

The sum of numbers in the Array are:


Sum = 44
While
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication13
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the integer number A");
int a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the integer number B");
int b = Convert.ToInt32(Console.ReadLine());
int sum = 0;
while(a<=b)
{
sum += a;
a++;
}
Console.WriteLine("sum from A to B is{0}",sum);
Console.ReadKey();
}
}
}
Output

Enter the integer number A


5
Enter the integer number B
10
sum from A to B is45

Result
Thus the program was executed successfully and the output was verified.
EX NO: 02
Change color of label text control
DATE: 14.02.2022 programmatically in ASP.NET

Aim

To write a program to change color of Label Text control programmatically in Asp.Net.

Algorithm

 Open the Visual Studio.


 New →Project →Visual C# →Web →Asp.Net →web application.
 Web Application2 → Add → New item → Web form.
 Click on form design.
 Select label from toolbox.
 Select Buttons from toolbox.
 Write coding for button1, button2 and button3.
 Save and run the form.
Program Coding

Source code

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs"


Inherits="WebApplication1.WebForm2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Welcome to all"></asp:Label>
<br /><br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Red"/>
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Blue"
Width="62px" />
<asp:Button ID="Button3" runat="server" onclick="Button3_Click"
style="margin-left: 0px" Text="Green" />
<br />
</div>
</form>
</body>
</html>

Button Click

using System;
using System.Collections;
using System.Configuration;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace WebApplication1
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Font.Name = "Arial";
Label1.Font.Bold = true;
Label1.ForeColor = Color.Red;
Label1.Font.Italic = true;
}
protected void Button2_Click(object sender, EventArgs e)
{
Label1.Font.Name = "Times new Roman";
Label1.Font.Bold = true;
Label1.ForeColor = Color.Blue;
Label1.Font.Strikeout = true;
Label1.Font.Size = FontUnit.Large;
}
protected void Button3_Click(object sender, EventArgs e)
{
Label1.Font.Name = "Bookman Old";
Label1.Font.Bold = true;
Label1.ForeColor = Color.Green;
Label1.Font.Italic = true;
Label1.Font.Size = FontUnit.Large;
}
}
}
Output
Result

Thus the program was executed successfully and the output as verified.
EX NO: 03
Type casting Methods
DATE: 21.02.2022

Aim

To write a C# program to perform Type Casting Methods.

Algorithm

 Open Visual Studio.


 Next click on
 Click on file → New → Project → visual c#→Console Application.
 Write the coding for conversion of one data type into another.
 Write the program for two types of conversion that is Implicit type conversion and
Explicit type conversion.
 Save the file and Run the program to get the output.
Program Coding

Explicit Type Conversion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ExplicitTypeconversion
{
class Program
{
static void Main(string[] args)
{
double d = 5673.74;
int i;
i=(int)d;
Console.WriteLine(i);
Console.ReadKey();
}
}
}
Output

5673
Implicit Type Conversion

using System;
using System.Collections.Generic;
using System.Text;

using System;

namespace ImplicitTypeConversion
{
class Program
{
static void Main(string[] args)
{
int numInt = 500;

// get type of numInt


Type n = numInt.GetType();

// Implicit Conversion
double numDouble = numInt;

// get type of numDouble


Type n1 = numDouble.GetType();

// Value before conversion


Console.WriteLine("Int value: " + numInt);
Console.WriteLine("Int Type: " + n);

// Value after conversion


Console.WriteLine("Double value: " + numDouble);
Console.WriteLine("Double Type: " + n1);
Console.ReadLine();
}
}
}
Output

Int value: 500

Int Type: System.Int32

Double value: 500

Double Type: System.Double

Result

Thus the program was executed successfully and the output was verified.
EX NO: 04
Thus the program was executed successfully and the output was verified
Convert Infix notation to Postfix notation.
DATE: 28.02.2022

Aim

To write a C# code to convert infix notation to postfix notation.

Algorithm

 Open Visual Studio.


 Select file → New → Project →visual C#→ Console Application.
 New give the coding for infix to postfix conversion.
 In infix expression, the operators will be placed in between the operands.
 In postfix expression, the operators will be place after the operands according to the
priority of operators.
 Write the coding to perform this.
 Now save and run the file.
 The output will be displayed.
Program coding
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace infix
{
class Program
{
static bool Convert(ref string infix,out string postfix)
{
int prio = 0;
postfix = "";
Stack<char> s1 = new Stack<char>();
for (int i = 0; i < infix.Length; i++)
{
char ch = infix[i];
if (ch == '+' || ch == '-' || ch == '*' || ch == '/')
{
if (s1.Count <= 0)
s1.Push(ch);
else
{
if (s1.Peek() == '*' || s1.Peek() == '/')
prio = 1;
else
prio = 0;
if (prio == 1)
{
if (ch == '+' || ch == '-')
{
postfix += s1.Pop();
i--;
}
else
{
postfix += s1.Pop();
i--;
}
}
else
{
if (ch =='+'||ch=='-')
{
postfix += s1.Pop();
s1.Push(ch);
}
else
s1.Push(ch);
}
}
}
else
{
postfix += ch;
}
}
int len = s1.Count();
for (int j = 0; j <len; j++)
postfix += s1.Pop();
return true;
}
static void Main(string[] args)
{
string infix = "";
string postfix = "";
if(args.Length==1)
{
infix = args[0];
Convert(ref infix, out postfix);
System.Console.WriteLine("Infix :\t" + infix);
System.Console.WriteLine("Postfix :\t" + postfix);
}
else
{
infix="a+b*c-d";
Convert(ref infix, out postfix);
System.Console.WriteLine("Infix :\t" + infix);
System.Console.WriteLine("Postfix :\t" + postfix);
System.Console.WriteLine();
infix = "a+b*c-d/e*f";
Convert(ref infix, out postfix);
System.Console.WriteLine("Infix :\t" + infix);
System.Console.WriteLine("Postfix :\t" + postfix);
System.Console.WriteLine();
infix="a-b/c*d-e--f/b*i++";
Convert(ref infix, out postfix);
System.Console.WriteLine("Infix :\t" + infix);
System.Console.WriteLine("Postfix :\t" + postfix);
System.Console.WriteLine();
Console.ReadLine();
}
}
}
Output

Infix : a+b*c-d

Postfix : abc*+d-

Infix : a+b*c-d/e*f

Postfix : abc*+de/f*-

Infix : a-b/c*d-e--f/b*i++

Postfix : abc/d*-e--fb/i*-++

Result

Thus the program was executed successfully and the output was verified.
EX NO: 05
Convert Digits to Words

DATE: 03.03.2022

Aim

To write a C# program for converting digits to words.

Algorithm

 Click on Visual Studio and open it.


 Select File → New → Project → Visual C#→Console Application.
 Write the coding for conversion of numbers to words.
 Use do while loop for incrementing the numbers.
 Save the file and run the program to get the output.
Program coding

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;
namespace numbertoword
{
class Program
{
static void Main(string[] args)
{
int number;
int nextDigit;
int numDigits;
int[] n = new int[20];
String[]
digits={"Zero","one","Two","Three","Four","Five","Six","Seven","Eight","Nine"};
Console.WriteLine("Enter any number");
number = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Entered number is:" + number);
Console.Write("Number in words:");
nextDigit = 0;
numDigits = 0;
do
{
nextDigit = number % 10;
n[numDigits] = nextDigit;
numDigits++;
number = number / 10;
}while (number > 0);
numDigits--;
for ( ; numDigits >= 0; numDigits--)
Console.Write(digits[n[numDigits]] + "");
Console.WriteLine();
Console.ReadLine();
}
}
}
Output

Enter any number

19856321

Entered number is:19856321

Number in words: one Nine Eight Five Six Three Two one

Result

Thus the program was executed successfully and the output was verified.
EX NO: 06
Increase and Decrease font size
DATE: 10.03.2022 programmatically

Aim

To create C# program to increase and decrease font size programmatically in Visual


Studio.

Algorithm

 Open Visual Studio.


 Click on File → New → Project → Select Visual C#→Windows forms applications.
 In windows form application click on toolbox and insert buttons, Rich text box and labels
as your convenience to make a form.
 Now double click on buttons to create coding for that form design.
 Save the form.
 Run the form to see the Output.
Program coding

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace fontsize
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
FontDialog fd=new FontDialog();
if (fd.ShowDialog() == DialogResult.OK)
{
richTextBox1.Font=fd.Font;
}
}
private void button2_Click(object sender, EventArgs e)
{
ColorDialog col = new ColorDialog();
col.ShowDialog();
richTextBox1.SelectionColor=col.Color;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
Output

Result

Thus the program was executed successfully and the output was verified.
EX NO: 07
Develop a console application to demonstrate

DATE: 21.03.2022 the branching in C#

Aim

To write a C# code for demonstrate the branching.

Algorithm

 Open the Visual Studio.


 Click on New →Project → Visual C# → Console Application
 Implement the separate coding for various branching operations such as goto, continue,
break etc.
 Save and run the application to get the output.
Program Coding

Break Statement

using System;
using System.Collections.Generic;
using System.Text;
namespace breakexample
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Example of Break Statement:");
Console.WriteLine("--------------------------");
for(int i=1;i<=4;i++)
{
if(i==3)
break;
Console.WriteLine("The Value of i is:{0}",i);
}
Console.WriteLine("Press any key to exit...");
Console.ReadLine();
}
}
}
Output

Example of Break Statement:

-----------------------------------

The Value of i is: 1

The Value of i is: 2

Press any key to exit...


Continue Statement

using System;
using System.Collections.Generic;
using System.Text;
namespace @continue
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("USE OF CONTINUE STATEMENT:");
Console.WriteLine("-------------------------");
for (int x = 1; x <= 6; x++)
{
if (x == 5)
continue;
Console.WriteLine("The value of x is:{0}", x);
}
Console.WriteLine("Press any key to exit.....");
Console.ReadLine();
}
}
}
Output

USE OF CONTINUE STATEMENT:

---------------------------------------------

The value of x is:1

The value of x is:2

The value of x is:3

The value of x is:4

The value of x is:6

Press any key to exit.....


Goto Statement

using System;
using System.Collections.Generic;
using System.Text;
namespace goto1
{
class Program
{
static void Main(string[] args)
{
//label
repeat:
Console.WriteLine("Enter a number less than 10");
int num = Convert.ToInt32(Console.ReadLine());
if(num>=10)
{
//Transfers control to repeat
goto repeat;
}
Console.WriteLine(num+ "is less than 10");
Console.ReadLine();
}
}
}
Output

Enter a number less than 10

8 is less than 10

Result

Thus the program was executed successfully and the output was verified.
EX NO: 08
Multilevel Inheritance
DATE: 28.03.2022

Aim

To write C# a code to perform multilevel inheritance.

Algorithm

 Open Visual Studio.


 Select Visual C#.
 Click on file →New → Project.
 Create a parent class person with public access.
 Get student name and register number as Input.
 Create a class student that inherits the person class.
 Give the name of class incharge.
 Create a class detail that inherits student class.
 Give the details of student Address.
 Create a class text class to display details form all the classes.
 Save the file and run to get the output.
Program Coding

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
public class person
{
protected string regno,name;
public void get()
{
Console.WriteLine("Multilevel inheritence");
Console.WriteLine("----------------------");
Console.WriteLine("Enter the Register Number:");
regno = Console.ReadLine();
Console.WriteLine("Enter the name of the student:");
name = Console.ReadLine();
}
public virtual void display()
{
Console.WriteLine("The register number of the student is {0} & the name of the student is
{1}",regno,name);
Console.ReadLine();
}
}
class student:person
{
public string classincharge="Mrs.Anitha";
public override void display()
{
base.display();
Console.WriteLine("Class in charge of student is {0}", classincharge);
}
}
class Details:student
{
private string StudentAddress="SRM University,Girls hostel,Chennai";
public void display()
{
Console.WriteLine("Student address:{0}",StudentAddress);
}
}
class textclass
{
public static void Main()
{
student s = new student();
s.get();
s.display();
Details d = new Details();
d.display();
Console.ReadKey();
Console.ReadKey();
}
}
}
Output

Multilevel inheritance

---------------------------

Enter the Register Number:

201

Enter the name of the student:

Abi

The register number of the student is 201 & the name of the student is Abi

Class in charge of student is Mrs.Anitha

Student address: SRM University, Girls hostel, Chennai

Result

Thus, the program was executed successfully and the output was verified.
EX NO: 09
Polymorphism

DATE: 05.04.2022

Aim

To write a C# code to perform polymorphism.

Algorithm

Method Overloading

 Click on Visual Studio.


 Select file -> New -> Project -> Visual C# -> Console Application.
 Create a class ADD1 to perform integer and float addition.
 Create a class ADD2 that Inherit ADD1 class to add string.
 Create a class program to invoke both classes.
 Save the file and run to get the output.

Method Overriding

 Click on Visual Studio.


 Select file -> New -> Project -> Visual C# -> Console Application.
 Create a class shape and declare length, width.
 Create a class rectangle that inherits shape and overrides area
 Create a class triangle that inherits shape and overrides area.
 Create a class caller to calculate area.
 Create a class tester to calculate area of Rectangle, Triangle.
 Save the file and run to get the output.
Method Overloading

Program coding
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace polymorphism
{
class ADD1
{
public void add(int a, int b)
{
Console.WriteLine(a + b);
}
public void add(float x, float y)
{
Console.WriteLine(x + y);
}
}
class ADD2:ADD1
{
public void add(string s1, string s2)
{
Console.WriteLine(s1 + s2);
}
}
class program
{
public static void Main(string[] args)
{
ADD2 obj = new ADD2();
obj.add(15, 400);
obj.add("Vijaya", "kumar");
Console.WriteLine("Press any to exit");
Console.ReadKey();
}
}
}
Output

415

Vijayakumar

Press any to exit


Method Overriding

Program coding

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace poly2
{
class shape
{
protected int length, width;
public shape(int a, int b)
{
length = a;
width = b;
}
public virtual int area()
{
Console.WriteLine("parent class area");
return 0;
}
}
class Rectangle : shape
{
public Rectangle(int a, int b)
: base(a, b)
{
}
public override int area()
{
Console.WriteLine("Rectangle class area:");
return (length * width);
}
}
class Triangle : shape
{
public Triangle(int a, int b)
: base(a, b)
{
}
public override int area()
{
{
Console.WriteLine("Triangle class area:");
return (length*width/2);
}
}
class caller
{
public void callArea(shape sh)
{
int a;
a = sh.area();
Console.WriteLine("Area:{0}", a);
}
}
class Tester
{
static void Main(string[] args)
{
caller c = new caller();
Rectangle r = new Rectangle(15, 7);
Triangle t = new Triangle(20, 5);
c.callArea(r);
c.callArea(t);
Console.ReadKey();
}
}
}
}
Output

Rectangle class area:

Area:105

Triangle class area:

Area:50

Result

Thus the program was executed successfully and the output was verified.
EX NO: 10
Currency conversion for Rupees to

DATE: 08.04.2022 Dollar, Franc and Euro

Aim

To write a code to convert currency conversion for rupees to dollar, franc, euro.

Algorithm

 Open Visual Studio.


 Click on file → New → Project → Visual C# -> Console Application.
 Display the choice for conversion using Console.WriteLine ( ).
 Convert the Indian rupees to franc and Indian rupees to dollar and rupees to euro.
 Use switch case for the selection of choice.
 Use the formula for conversion of rupees to dollar, franc and euro.
 Save the file and run it to get the output.
Program coding

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;
namespace rupees
{
class Program
{
static void Main(string[] args)
{
while(true)
{
Console.WriteLine("Enter your choice:");
Console.WriteLine("1.Rupees to France");
Console.WriteLine("2.Rupees to dollar:");
Console.WriteLine("3.Rupees to euro:");
Console.WriteLine("4.Exit");
int choice = int.Parse(Console.ReadLine());
switch (choice)
{
case 1:
franc();
break;
case 2:
dollar();
break;
case 3:
euro();
break;
case 4:
break;
default:
Console.WriteLine("Enter valid choice");
break;
}
if
(choice == 4)
break;}
Console.ReadKey();
}
static void franc()
{
Console.WriteLine("Enter amount in Rupees:");
double r=double.Parse(Console.ReadLine());
double f=r/83.52;
Console.Write("franc:\t{0}\n",f);
}
static void dollar()
{
Console.WriteLine("Enter amount in Rupees:");
double r=double.Parse(Console.ReadLine());
double d=r/76.90;
Console.WriteLine("dollar :{0}\n",d);
}
static void euro()
{
Console.WriteLine("Enter amount in Rupees:");
double r=double.Parse(Console.ReadLine());
double e=r/83.65;
Console.Write("euro:\t{0}\n",e);
}}}
Output

Enter your choice:


1.Rupees to France
2.Rupees to dollar:
3.Rupees to euro:
4.Exit
1
Enter amount in Rupees:
25
franc: 0.299329501915709
Enter your choice:
1.Rupees to France
2.Rupees to dollar:
3.Rupees to euro:
4.Exit
2
Enter amount in Rupees:
42
dollar :0.546163849154746

Enter your choice:


1.Rupees to France
2.Rupees to dollar:
3.Rupees to euro:
4.Exit
3
Enter amount in Rupees:
75
euro: 0.896592946802152
Enter your choice:
1.Rupees to France
2.Rupees to dollar:
3.Rupees to euro:
4.Exit
4

Result

Thus the program was executed successfully and the output was verified.
EX NO: 11
String Functions

DATE: 19.04.2022

Aim

To write a C# code to perform string functions.

Algorithm

 Click on Visual Studio.


 Select File →New project → Visual C#→ Console application.
 Declare the two strings for the string operation.
 Clone the string using a clone( ).
 To find the letters in the string use a contains( ).
 To check the equality of the string use (a equals (b)).
 Like these perform all other string operations using various string functions.
 Save and run the program.
Program coding

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace String
{
class Program
{
static void Main(string[] args)
{
string A, B;
A = "Hello World";
B = "World";
Console.WriteLine(A.Clone());
Console.WriteLine(A.Contains("llo"));
Console.WriteLine(A.EndsWith("o"));
Console.WriteLine(A.Equals(B));
Console.WriteLine(A.GetHashCode());
Console.WriteLine(A.GetType());
Console.WriteLine(A.GetTypeCode());
Console.WriteLine(A.IndexOf("e"));
Console.WriteLine(A.ToLower());
Console.WriteLine(A.ToUpper());
Console.WriteLine(A.Insert(0,"Hai"));
Console.WriteLine(A.IsNormalized());
Console.WriteLine(A.LastIndexOf("b"));
Console.WriteLine(B.Length);
Console.WriteLine(B.Remove(2));
Console.WriteLine(B.Replace("o","i"));
string[] Split = A.Split(new char[] { 'e' });
Console.WriteLine(Split[0]);
Console.WriteLine(Split[1]);
Console.WriteLine(B.StartsWith("H"));
Console.WriteLine(A.Substring(2,5));
Console.WriteLine(A.ToCharArray());
Console.WriteLine(A.Trim());
Console.ReadKey();
}
}
}
Output

Hello World
True
False
False
1411332840
System.String
String
1
hello world
HELLO WORLD
HaiHello World
True
-1
5
Wo
Wirld
H
llo World
False
llo W
Hello World
Hello World

Result

Thus the program was executed successfully and the output was verified.
EX NO: 12
Program containing a List Box, a Button an Image
DATE: 26.04.2022 and Label

Aim

To write a program containing a list box, a button, an image and a label in ASP.Net.

Algorithm

 Open the Visual Studio.


 File →New → Website → Asp.Net Empty website.
 In the application right click and select Add → New items → Web forms.
 Select label from toolbox and drag that to the design window.
 Now name the label with the title as per the wish.
 Now select and drag the list box and give the content for the design.
 Likewise, in the design window drag the button and image box.
 Then add the image.
 Click on the Button. The Console Window will open give the coding for the design.
 Now Save and run the Program.
Program coding
Source Code

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"


Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.style1
{
font-size: x-large;
color: #0000FF;
font-weight: bold;
}
.style2
{
color: #0000FF;
}
.style3
{
color: #0000FF;
font-weight: bold;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<span class="style2">
<b>
</b></span>
<span class="style1">Mahi Shop</span><span class="style3">
</span><b></b>
<br />
<br />
<asp:ListBox ID="ListBox1" runat="server" Height="134px" Width="228px"
style="color: #FF3399">
<asp:ListItem Value="100">bangles</asp:ListItem>
<asp:ListItem Value="500">chain</asp:ListItem>
<asp:ListItem Value="70000">goldchain</asp:ListItem>
<asp:ListItem Value="200">jummki</asp:ListItem>
<asp:ListItem Value="900">kolusu</asp:ListItem>
</asp:ListBox>
<br />
</div>
<asp:Image ID="Image1" runat="server" Height="238px" Width="225px"
style="color: #FFFFCC" />
<p>
<asp:Button ID="Button1" runat="server" Height="37px" Text="Click know the price"
Width="231px" style="color: #CC0000" />
</p>
<p>
</p>
<p>
<asp:Label ID="Label1" runat="server" Text="Prize:"></asp:Label>
</p>
</form>
</body>
</html>
Button Click

Partial Class _Default

Inherits System.Web.UI.Page

Protected Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As


System.EventArgs) Handles ListBox1.SelectedIndexChanged

If (ListBox1.SelectedIndex = 0) Then

Image1.ImageUrl = ".\images\bangles1.jfif"

ElseIf (ListBox1.SelectedIndex = 1) Then

Image1.ImageUrl = ".\images\chain1.jfif"

ElseIf (ListBox1.SelectedIndex = 2) Then

Image1.ImageUrl = ".\images\goldchain.jfif"

ElseIf (ListBox1.SelectedIndex = 3) Then

Image1.ImageUrl = ".\images\jummki.jfif"

ElseIf (ListBox1.SelectedIndex = 4) Then

Image1.ImageUrl = ".\images\kolusu.jfif"

End If

End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Button1.Click

Label1.Text = ListBox1.SelectedValue

End Sub

End Class
Output
Result

Thus the program was executed successfully and the output was verified.
EX NO: 13
Validation Control
DATE: 04.05.2022

Aim

To write a program to demonstrate the validation controls in Asp.Net.

Algorithm

 Open the Visual Studio.


 File → New → Project → Visual C# → Web →Asp.net web form Application.
 Right click on the application → Add → New item → Web Form.
 Click on design and design your web form.
 And add all the validation controls such as compare validator, Range validator, Regular
expression validator, Required field validator and validation summary in required field.
 Give coding for submit button.
 Now run the application to get the output.
Program Coding
Source Code

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"


Inherits="Validation._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.style1
{
width: 90%;
height: 206px;
}
.style2
{
width: 226px;
}
.style3
{
width: 100px;
}
.style4
{
width: 226px;
height: 26px;
}
.style5
{
height: 26px;
}
.style6
{
width: 100px;
height: 26px;
}
.style7
{
width: 17px;
}
.style8
{
height: 26px;
width: 17px;
}
.style9
{
width: 11px;
}
.style10
{
height: 26px;
width: 11px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="REGISTRATION FROM"></asp:Label>
<br />
<br />
<table class="style1">
<tr>
<td class="style2">
ENTER NAME</td>
<td class="style9">
&nbsp;</td>
<td class="style3">
<asp:TextBox ID="name" runat="server"></asp:TextBox>
</td>
<td class="style7">
<td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="Please enter name"
ControlToValidate="name">*</asp:RequiredFieldValidator>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style2">
ENTER AGE</td>
<td class="style9">
</td>
<td class="style3">
<asp:TextBox ID="age" runat="server"></asp:TextBox>
</td>
<td class="style7">
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ErrorMessage="Please enter your age"
ControlToValidate="age">*</asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="age"
ErrorMessage="Age must between 18 to 60" MaximumValue="60" MinimumValue="18">Age
must between 18 to 60</asp:RangeValidator>
</td>
<td></td>
<td></td>
</tr><tr>
<td class="style2">
ENTER EMAIL ID</td>
<td class="style9">
</td>
<td class="style3">
<asp:TextBox ID="email" runat="server"></asp:TextBox>
</td>
<td class="style7"></td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ErrorMessage="Please enter your email id"
ControlToValidate="email">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="email" ErrorMessage="Please enter valid email id"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">Please
enter valid email</asp:RegularExpressionValidator>
</td><td>
</td><td>
</td></tr>
<tr>
<td class="style2">
ENTER PASSWORD</td>
<td class="style9">
</td>
<td class="style3">
<asp:TextBox ID="pw" runat="server" TextMode="Password"></asp:TextBox>
</td>
<td class="style7">
</td><td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ErrorMessage="Please enter your password"
ControlToValidate="pw">*</asp:RequiredFieldValidator>
</td><td>
</td><td>
</td></tr>
<tr>
<td class="style4">
ENTER RETYPE PASSWORD</td>
<td class="style10">
</td>
<td class="style6">
<asp:TextBox ID="rpw" runat="server" TextMode="Password"></asp:TextBox>
</td>
<td class="style8">
</td>
<td class="style5">
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ErrorMessage="Please enter your retype password"
ControlToValidate="rpw">*</asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="pw" ControlToValidate="rpw"
ErrorMessage="password not match.retype">password not
match.retype</asp:CompareValidator>
</td>
<td class="style5">
</td>
<td class="style5">
</td>
</tr>
<tr>
<td class="style4">
ENTER CITY</td>
<td class="style10">
</td>
<td class="style6">
<asp:TextBox ID="city" runat="server" ontextchanged="city_TextChanged"></asp:TextBox>
</td>
<td class="style8">
</td>
<td class="style5">
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
ErrorMessage="Please enter your city"
ControlToValidate="city">*</asp:RequiredFieldValidator>
</td>
<td class="style5">
</td>
<td class="style5">
</td>
</tr>
<tr>
<td class="style2">
ENTER MOBILE NUMBER</td>
<td class="style9">
</td>
<td class="style3">
<asp:TextBox ID="mn" runat="server"></asp:TextBox>
</td>
<td class="style7">
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server"
ErrorMessage="Please enter your Mobile Number"
ControlToValidate="mn">*</asp:RequiredFieldValidator>
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
</div>
<p>
<asp:Label ID="Label2" runat="server"></asp:Label>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="SUBMIT" />
</p>
</form>
</body>
</html>
Button Click
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
namespace Validation
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Label2.Text = "page submitted successfully";
}
protected void city_TextChanged(object sender, EventArgs e)
{
}
}
}
Output
Result

Thus the program was executed successfully and the output was verified.
EX NO: 14
Web Server Control
DATE: 11.05.2022

Aim

To write a program to various web server controls in web application.

Algorithm

 Open the Visual Studio.


 File click on file → New → Project → Visual C# →ASP.Net web application.
 Right click on the application → Add → New item → Web form.
 Click on the design and design your web form.
 In the form include various web server controls such as check box, Radio Button, Text
box, label etc..,
 In addition, give coding for submit button.
 Now run the application go get the output for web server controls
Program Coding
Source code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="WebApplication10.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Student Registration</h1>
<p>Name:<asp:TextBox ID ="TextBox1" runat="server"></asp:TextBox></p>
<p>Email Id:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></p>
<p>Course:<asp:TextBox ID="Textbox3" runat="server"></asp:TextBox></p>
<p>Gender:
<asp:RadioButton ID ="RadioButton1" runat ="server" Text="Male" GroupName ="Gender" />
<asp:RadioButton ID="RadioButton2" runat ="server" Text ="Female" GroupName="Gender"
/>
</p>
<p>Sports:
<asp:CheckBox ID="CheckBox1" runat ="server" Text="Cricket" />
<asp:CheckBox ID="CheckBox2" runat ="server" Text="Badminton" />
<asp:CheckBox ID="CheckBox3" runat ="server" Text="Kabbadi" />
<asp:CheckBox ID="CheckBox4" runat ="server" Text="Footbal" />
</p>
<p><asp:Button ID ="Button1" runat ="server" OnClick="Button_Click" Text="Submit" /></p>
</div>
<asp:Label ID="Label1" runat="server" ></asp:Label><br /><br />
<asp:Label ID="Label2" runat="server" ></asp:Label><br /><br />
<asp:Label ID="Label3" runat="server" ></asp:Label><br /><br />
<asp:Label ID="Label4" runat="server" ></asp:Label><br /><br />
<p>
<asp:Label ID="Label5" runat="server" ></asp:Label><br /><br />
</p>
</form>
</body>
</html>

Button Click
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
usingSystem.Web.UI.WebControls;
namespace WebApplication10
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Button_Click(object sender, EventArgs e)
{
String name = TextBox1.Text;
String email = TextBox2.Text;
String course = Textbox3.Text;
String gender = "";
String Sports="";
if(RadioButton1.Checked)
gender=RadioButton1.Text;
else
gender=RadioButton2.Text;
if(CheckBox1.Checked)
Sports=CheckBox1.Text+"";
if(CheckBox2.Checked)
Sports=CheckBox2.Text+"";
if(CheckBox3.Checked)
Sports=CheckBox3.Text+"";
if(CheckBox4.Checked)
Sports=CheckBox4.Text+"";
Label1.Text="Name:"+name;
Label2.Text="Email id:"+email;
Label3.Text="Course:"+course;
Label4.Text="Gender:"+gender;

Label5.Text="sports:"+Sports;
}
}
Output

Result

Thus the program was executed successfully and the output was verified.
EX NO: 15
Develop a basic windows
DATE: 18.05.2022 phone application

Aim
To develop a basic windows phone Application.

Algorithm

 Open Visual Studio 2022.


 Click create a new project.
 Select Mobile app (Xamarian form).
 Click next give project title and click create.
 In tools menu click Android → Android SDK manager.
 And check the platforms and needed tools and click apply changes.
 Again in tools menu click Android → Android Device manager
 Create the Android mobile App with Pixel 5 – API 30 and Android version 11.0.
 Now you run the project to start the Emulator.
Program Coding
using System;
using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.OS;
namespace App2.Droid
{
[Activity(Label = "App2", Icon = "@mipmap/icon", Theme = "@style/MainTheme",
MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize |
ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout |
ConfigChanges.SmallestScreenSize )]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions,
[GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions,
grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}
Output

Result
Thus the application ran succuessfully and the output was verified.

You might also like