19IT470 3IT42 PracticalFile
19IT470 3IT42 PracticalFile
using System;
namespace LAB
{
class manual_1_1
{
static void Main(string[] args)
{
Console.WriteLine("hello World!");
Console.ReadKey();
}
}
}
using System;
namespace LAB
{
class manual_1_2
{
public static void Main(String[] args)
{
int n,m;
Console.Write("Enter the layers of the pyramid:");
n=Convert.ToInt32(Console.ReadLine());
m=n;
for (int i = 1; i<= n; i++)
{
for (int j = 1; j <= m - 1; j++)
{
Console.Write(" ");
}
i
for (int k = 1; k <= 2 * i - 1; k++)
3IT42: Dot Net Technology
{
Console.Write("*");
}
m--;
Console.WriteLine("");
}
}
}
using System;
namespace LAB
{
class manual_1_3
{
static void Main(string[] args)
{
Console.WriteLine("Enter a No. to
reverse"); int Number =
int.Parse(Console.ReadLine()); int Reverse =
0;
while (Number > 0)
{
int remainder = Number % 10;
Reverse = (Reverse * 10) +
remainder; Number = Number / 10;
}
Console.WriteLine("Reverse No. is {0}", Reverse);
Console.ReadLine();
}
}
}
3IT42: Dot Net Technology
using System;
namespace LAB
{
class manual_1_4
{
static void Main(string[] args)
{
int num1, num2, num3;
num1 = 10;
num2 = 20;
num3 = 50;
if (num1 > num2)
{
if (num1 > num3)
{
Console.Write("Number one is the largest!\n");
}
else
{
Console.Write("Number three is the largest!\n");
}
}
else if (num2 > num3)
Console.Write("Number two is the largest!\n");
else
Console.Write("Number three is the largest!\n");
}
}
}
3IT42: Dot Net Technology
using System;
namespace practical1
{
class sortarray
{
public static void Main()
{
int[] arr = new int[] { 10,9,8,7,6,5,4,3,2,1 };
int temp = 0;
Practical 2.(a) Write C# code to prompt a user to input his/her name and country name
and then the output will be shown as an example below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LAB
{
class manual_2_1
{
static void Main(string[] args)
{
Console.WriteLine("Enter your name:");
string name = Console.ReadLine();
Console.ReadKey();
}
}
}
3IT42: Dot Net Technology
Practical 2.(b) Write C# code to perform various string manipulation command on string.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LAB
{
class maunal_2_2
{
static void Main(string[] args)
{
int x=0,y=0;
Console.WriteLine("Enter the value of x");
x=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the value of y");
y=Convert.ToInt32(Console.ReadLine());
int add=0,sub=0,mult=0,div=0;
add=x+y;
sub=x-y;
mult=x*y;
div=x/y;
Console.WriteLine("Addition of x and y is {0}",add);
Console.WriteLine("Subtraction of x and y is {0}",sub);
Console.WriteLine("Multiplication of x and y is {0}",mult);
Console.WriteLine("Division of x and y is {0}",div);
Console.ReadLine();
}
}
}
3IT42: Dot Net Technology
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LAB
{
class Box
{
public int x,y,z;
public Box(int x, int y, int z)
{
this.x = x;
this.y = y;
this.z = z;
}
public Box(Box copybox)
{
this.x =
copybox.x; this.y
= copybox.y; this.z
= copybox.z;
}
}
class maunal_3_1
{
static void Main(string[] args)
{
Box cube = new Box(10, 10, 10);
Box copycube = new Box(cube);
Console.WriteLine("Dimenseions of the cube are {0} {1} {2}", cube.x, cube.y, cube.z);
Console.WriteLine("Dimenseions of the copycube are {0} {1} {2}", copycube.x, copycube.y,
copycube.z);
}
}
}
3IT42: Dot Net Technology
2. Destructor
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LAB
{
class Box
{
public int x,y,z;
public Box(int x, int y, int z)
{
this.x = x;
this.y = y;
this.z = z;
}
public Box(Box copybox)
{
this.x =
copybox.x; this.y
= copybox.y; this.z
= copybox.z;
}
~Box()
{
Console.WriteLine("Box destructor called");
}
}
class maunal_3_2
{
static void Main(string[] args)
{
Box cube = new Box(10, 10, 10);
Console.WriteLine("Dimenseions of the cube are {0} {1} {2}", cube.x, cube.y, cube.z);
}
}
}
3IT42: Dot Net Technology
3. Method Overloading
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LAB
{
class Add
{
public int Addition(int a, int b)
{
return a + b;
}
public int Addition(int a, int b, int c)
{
return a + b + c;
}
}
class maunal_3_3
{
static void Main(string[] args)
{
Add obj = new Add();
Console.WriteLine(obj.Addition(10, 20));
Console.WriteLine(obj.Addition(10, 20, 30));
}
}
}
3IT42: Dot Net Technology
4. Properties
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LAB
{
class Name
{
private string
firstName; private
string lastName; public
string FirstName
{
get
{
return firstName;
}
set
{
firstName = value;
}
}
public string LastName
{
get
{
return lastName;
}
set
{
lastName = value;
}
}
public string FullName
{
get
{
return firstName + " " + lastName;
}
}
}
class maunal_3_4
{
static void Main(string[] args)
3IT42: Dot Net Technology
{
Name name = new Name();
name.FirstName = ("Sanket");
name.LastName = "Detroja";
Console.WriteLine(name.FullName);
}
}
}
5. Inheritance
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LAB
{
class Parent
{
public void Method()
{
Console.WriteLine("Parent.Method");
}
}
class Child : Parent
{
public new void Method()
{
Console.WriteLine("Child.Method");
}
}
class maunal_3_5
{
static void Main(string[] args)
{
Parent p = new Parent();
p.Method();
3IT42: Dot Net Technology
6. Exception Handling
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LAB
{
class Division
{
public int result = 0;
public void division (int a, int b)
{
try
{
result = a / b;
}
catch (DivideByZeroException e)
{
Console.WriteLine("Divide by zero exception: " + (e.Message));
}
catch (Exception e)
{
Console.WriteLine("Exception: {0}", e.Message);
}
finally
{
Console.WriteLine("Result: {0}", result);
}
}
}
class maunal_3_6
3IT42: Dot Net Technology
{
static void Main(string[] args)
{
Division d = new Division();
d.division(10, 0);
}
}
}
7. Delegates
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LAB
{
class Calc
{
public delegate void addnum(int x, int y);
public delegate void subnum(int x, int y);
public delegate void mulnum(int x, int
y); public delegate void divnum(int x, int
y); public void add(int a , int b)
{
Console.WriteLine("Sum is : " + (a + b));
}
public void sub(int a, int b)
{
Console.WriteLine("Sub is : " + (a - b));
}
public void mul(int a, int b)
{
Console.WriteLine("Mul is : " + (a * b));
}
public void div(int a, int b)
{
3IT42: Dot Net Technology
8. Indexer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LAB
{
class IndexNaming
{
private string[] names = new string[10];
public string this[int i]
{
get
{
return names[i];
3IT42: Dot Net Technology
}
set
{
names[i] = value;
}
}
}
class maunal_3_8
{
static void Main(string[] args)
{
IndexNaming Team = new
IndexNaming(); Team[0] = "Sanket";
Team[1] = "Kunj";
Team[2] = "Sharthak";
Team[3] = "Brijesh";
Team[4] = "Kenil";
Team[5] = "Dharmil";
Team[6] = "Manoj";
Team[7] = "Bhagvanji";
Team[8] = "Vishal";
Team[9] = "Palak";
for (int i = 0; i< 10; i++)
{
Console.WriteLine(Team[i]);
}
}
}
}
3IT42: Dot Net Technology
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace manual_4_1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
}
3IT42: Dot Net Technology
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace manual_4_2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
- Now drag and drop the necessary tools from Toolbox shown below.
3IT42: Dot Net Technology
form ParentForm:
using System;
using System.Windows.Forms;
namespace inheritance
{
public partial class parentForm : Form
{
public parentForm()
{
InitializeComponent();
}
}
}
}
childForm:
using System;
namespace inheritance
{
public partial class childForm : parentForm
{
public childForm()
{
InitializeComponent();
}
3IT42: Dot Net Technology
}
}
}
Form 1:
using System;
using System.Windows.Forms;
namespace MIDform
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Form2 f2;
3IT42: Dot Net Technology
Form3 f3;
private void form2ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (f3 == null)
{
f3 = new Form3();
f3.MdiParent =
this; f3.Show();
}
else
{
f3.Activate();
}
}
}
}
Form 2:
using System;
using System.Windows.Forms;
namespace MIDform
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
}
}
}
Form3:
using System;
using System.Windows.Forms;
namespace MIDform
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
}
}
}
3IT42: Dot Net Technology
4. Write a program to demonstrate use of print dialog (print document, print preview control
and print setup)
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
3IT42: Dot Net Technology
namespace menuitemfinal
{
public partial class Form1 : Form
{
public string var = ""; public Form1()
{
InitializeComponent();
}
Practical 6. Create a window application for basic Dialog controls that will show the basic
property and methods of all that controls.
1. FolderBrowserDialog
2. OpenFileDialog
3. ColorDialog
4. FontDilalog
5. SaveFileDialog Control
using System;
using System.Windows.Forms;
namespace WindowsFormsApp6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
}
}
}
}
3IT42: Dot Net Technology
3IT42: Dot Net Technology
3IT42: Dot Net Technology
3IT42: Dot Net Technology
Practical 7. Create a window application for connection with sql server and perform basic
operations on database. (Insert , Update ,Delete) in ADO.NET
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Data.OleDb;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OleDbConnection conn;
OleDbCommand comm;
OleDbDataReader dreader;
string connstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\\Users\\smdetroja\\Desktop\\Database.mdb";
{
conn.Close();
}
}
try
{
dreader = comm.ExecuteReader();
if (dreader.Read())
{
textBox2.Text =
dreader[1].ToString(); textBox3.Text
= dreader[2].ToString();
textBox4.Text =
dreader[3].ToString();
}
else
{
MessageBox.Show(" No Record");
}
dreader.Close();
}
catch (Exception)
{
MessageBox.Show(" No Record");
}
finally
{
conn.Close();
}
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 1092px;
height: 307px;
}
.auto-style2 {
width: 360px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<table class="auto-style1">
<tr>
<td class="auto-style2">Username </td>
<td>
<asp:TextBox ID="TextBox1" runat="server"
OnTextChanged="TextBox1_TextChanged" Width="359px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server" ControlToValidate="TextBox1" ErrorMessage="Username Required"
ForeColor="Red" ValidationGroup="a"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style2">Password</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"
OnTextChanged="TextBox2_TextChanged" Width="359px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2"
runat="server" ControlToValidate="TextBox2" ErrorMessage="Password Required"
ForeColor="Red" ValidationGroup="a"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style2">Re-Password</td>
3IT42: Dot Net Technology
<td>
<asp:TextBox ID="TextBox3" runat="server"
OnTextChanged="TextBox3_TextChanged" Width="359px"></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="TextBox2" ControlToValidate="TextBox3" ErrorMessage="Password Not
Match" ForeColor="Red" ValidationGroup="a"
ValueToCompare="a"></asp:CompareValidator>
</td>
</tr>
<tr>
<td class="auto-style2">Fullname</td>
<td>
<asp:TextBox ID="TextBox4" runat="server"
OnTextChanged="TextBox4_TextChanged" Width="359px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3"
runat="server" ControlToValidate="TextBox4" ErrorMessage="Fullname Required"
ForeColor="Red" ValidationGroup="a"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style2">Email</td>
<td>
<asp:TextBox ID="TextBox5" runat="server"
OnTextChanged="TextBox5_TextChanged" Width="359px"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
runat="server" ControlToValidate="TextBox5" ErrorMessage="Enter Proper Email"
ForeColor="#FF3300" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
ValidationGroup="a"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="auto-style2">Age</td>
<td>
<asp:TextBox ID="TextBox6" runat="server"
OnTextChanged="TextBox6_TextChanged" Width="359px"></asp:TextBox>
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="TextBox6" ErrorMessage="Enter Correct Age"
ForeColor="#FF3300" MaximumValue="35" MinimumValue="18"
ValidationGroup="a"></asp:RangeValidator>
</td>
</tr>
<tr>
<td class="auto-style2">Country</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>Choose Country</asp:ListItem>
3IT42: Dot Net Technology
<asp:ListItem>India</asp:ListItem>
<asp:ListItem>USA</asp:ListItem>
<asp:ListItem>Germany</asp:ListItem>
<asp:ListItem>Canada</asp:ListItem>
<asp:ListItem>Australia</asp:ListItem>
<asp:ListItem>Japan</asp:ListItem>
<asp:ListItem>Newzealand</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="DropDownList1" ErrorMessage="Enter Country "
ForeColor="Red" ValidationGroup="a"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style2">Gender</td>
<td>
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
<asp:ListItem>Male</asp:ListItem>
<asp:ListItem>Female</asp:ListItem>
<asp:ListItem>Trans</asp:ListItem>
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ControlToValidate="RadioButtonList1" ErrorMessage="Enter Gender" ForeColor="Red"
ValidationGroup="a"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Save" ValidationGroup="a" />
</td>
</tr>
</table>
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
ForeColor="Black" ShowMessageBox="True" ValidationGroup="a" />
</form>
</body>
</html>
3IT42: Dot Net Technology
3IT42: Dot Net Technology
Practical 09. Create a web application that will use the concept of cookie, Response, request
and session object.
Cookie:
Using System;
Using System.Web;
Namespace WebFormsControlls
// Creating Cookie //
Kumar”;
Response.Cookies.Add(cokie);
// Fetching Cookie //
Label1.Text = co_val;
}
3IT42: Dot Net Technology
Default.aspx:
Inherits=”CoockieExample._Default” %>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<p>
3IT42: Dot Net Technology
</p>
</form>
Default.aspx.cs:
Using System;
Using System.Web.UI;
Namespace CoockieExample
Response.Cookies[“computer”].Expires = DateTime.Now.AddDays(-1);
Label2.Text = “”;
// Adding Coockies //
If (apple.Checked)
Response.Cookies[“computer”][“apple”] = “apple”;
If (dell.Checked)
Response.Cookies[“computer”][“dell”] = “dell”;
3IT42: Dot Net Technology
If (lenevo.Checked) Response.Cookies[“computer”]
[“lenevo”] = “lenevo”;
If (acer.Checked) Response.Cookies[“computer”]
[“acer”] = “acer”;
If (sony.Checked) Response.Cookies[“computer”]
[“sony”] = “sony”;
If (wipro.Checked) Response.Cookies[“computer”]
[“wipro”] = “wipro”;
// Fetching Cookies //
If (Request.Cookies[“computer”].Values.ToString() != null)
If (Request.Cookies[“computer”][“apple”] != null)
Label2.Text += Request.Cookies[“computer”][“apple”] + “
“; If (Request.Cookies[“computer”][“dell”] != null)
Label2.Text += Request.Cookies[“computer”][“dell”] + “
“; If (Request.Cookies[“computer”][“lenevo”] != null)
Label2.Text += Request.Cookies[“computer”][“lenevo”] + “
“; If (Request.Cookies[“computer”][“acer”] != null)
Label2.Text += Request.Cookies[“computer”][“acer”] + “
“; If (Request.Cookies[“computer”][“sony”] != null)
Label2.Text += Request.Cookies[“computer”][“sony”] + “
“; If (Request.Cookies[“computer”][“wipro”] != null)
Label2.Text += Request.Cookies[“computer”][“wipro”] + “ “;
Response.Cookies[“computer”].Expires = DateTime.Now.AddDays(-1);
3IT42: Dot Net Technology
}
3IT42: Dot Net Technology
}
3IT42: Dot Net Technology
Go to Visual Studio then click on "File" -> "Website" -> "ASP.NET empty website template".
Then provide the website name (for example: WebServiceSample).
namespace WebApplication4
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
return x / y;
}
}
}
Step 3:
To see whether the service is running correctly go to the Solution Explorer then open "Airthmatic.asmx"
and run your application.
3IT42: Dot Net Technology
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table border="2" cellpadding="2" cellspacing="2">
<tr>
<td align="right">
<asp:Label ID="Label1" runat="server" Text="Enter 1st Number"></asp:Label>
</td>
<td align="left">
<asp:TextBox ID="txtFno" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="Label2" runat="server" Text="Enter 2nd Number"></asp:Label>
</td>
<td align="left">
<asp:TextBox ID="txtSno" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="Label3" runat="server" Text="Result"></asp:Label>
</td>
<td align="left">
<asp:Label ID="lblResult" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td align="center">
<asp:Button ID="btnAdd" runat="server" Text="Add(+)"
OnClick="btnAdd_Click" />
</td>
<td align="center">
3IT42: Dot Net Technology
For this right click on reference and the click on add reference…
Then it will show you to option for adding WebService1.asmx to client’s web site.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
3IT42: Dot Net Technology
using System.Web.UI.WebControls;
namespace WebApplication4
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{