Net 1 8
Net 1 8
PRACTICAL 01
Code:
using System;
namespace practical1
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter your name");
string name=Console.ReadLine();
Console.WriteLine("enter your country");
string country=Console.ReadLine();
Console.WriteLine("hello "+name+" from country "+country);
}
}
}
Output:
Code:
using System;
namespace calculator
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter num 1");
int num1 = int.Parse(Console.ReadLine());
Console.WriteLine("Enter num2:");
int num2 = int.Parse(Console.ReadLine());
Console.WriteLine("1.Addition:");
1
12202040501079 Pushti Baldha
.NET Technology -202045604
Console.WriteLine("2.Subtarction:");
Console.WriteLine("3.Multiplication:");
Console.WriteLine("4.Division");
Console.WriteLine("Enter your choice");
int ch = int.Parse(Console.ReadLine());
switch (ch)
{
case 1:
Console.WriteLine("addition:" + (num1 + num2));
break;
case 2:
Console.WriteLine("subtarction" + (num1 - num2));
break;
case 3:
Console.WriteLine("Multiplicaation" + (num1 * num2));
break;
case 4:
Console.WriteLine("division" + (num1 / num2));
break;
default:
Console.WriteLine("kal ana");
break;
}
}
}
}
Output:
2
12202040501079 Pushti Baldha
.NET Technology -202045604
Practical-02
Write C# code to do the following
1) Perform Celsius to Fahrenheit Conversion and Fahrenheit to Celsius
conversion.
Code:
using System;
namespace ferenight_celcius
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the number to convert");
float num1 = float.Parse(Console.ReadLine());
Console.WriteLine("1.Fahrenheit to Celsius");
Console.WriteLine("2.Celsius to Fahrenheit");
Console.WriteLine("Enter your choice:");
int ch = int.Parse(Console.ReadLine());
switch (ch)
{
case 1:
Console.WriteLine("the Fahrenheit to Celsius is: " + (((num1 - 32) * 5)/ 9));
break;
case 2:
Console.WriteLine("the celsius to farehneit is: " + ((num1 * 9 / 5) - 32));
break;
default:
Console.WriteLine("choose coorect choice");
break;
}
}
}
}
Output:
3
12202040501079 Pushti Baldha
.NET Technology -202045604
Code:
using System;
namespace currency_convertor
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the rupees to get converted:");
double num1=double.Parse(Console.ReadLine());
Console.WriteLine(+num1+"Rupees to dollar = " + (num1 / 85.55));
Console.WriteLine(+num1 + "Ruppes to frank = " + (num1 / 94.09));
Console.WriteLine(+num1+"Rupees to euro = "+(num1/88.35));
}
}
}
Output:
4
12202040501079 Pushti Baldha
.NET Technology -202045604
PRACTICAL-03
Create console applications to implement following C# Concepts.
1. Static Constructor & Constructor Overloading.
2. Method Overloading
3. Structured Error Handling
4. Inheritance
5. Params parameter
6. Delegates and Events out and ref
public Account()
{
id = 0;
name="Account holder";
}
}
}
5
12202040501079 Pushti Baldha
.NET Technology -202045604
Output:
2) Method Overloading
Code:
using System;
using prac3_2;
namespace prac3_2
{
internal class Calculate
{
public void sqaure(int a)
{
Console.WriteLine("The square is:"+ (a*a));
}
public void sqaure(double a)
{
Console.WriteLine("The square is:" + (a * a));
}
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the number: ");
int a = int.Parse(Console.ReadLine());
Calculate c1=new Calculate();
c1.sqaure(a);
Output:
6
12202040501079 Pushti Baldha
.NET Technology -202045604
Code:
using System;
namespace prac3_3
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter num1:");
int i = int.Parse(Console.ReadLine());
Console.WriteLine("Enter num2:");
int j = int.Parse(Console.ReadLine());
try
{
int res;
res = (i / j);
Console.WriteLine("Result is:" + res);
}
catch (DivideByZeroException e)
{
Console.WriteLine(e.Message);
}
/*finally
{
Console.WriteLine("Enter correct input:");
}*/
}
}
}
Output:
7
12202040501079 Pushti Baldha
.NET Technology -202045604
4) Inheritance
Code:
using System;
class Animal
{
public void Speak()
{
Console.WriteLine("Animal speaks");
}
}
class Dog : Animal
{
public void Bark()
{
Console.WriteLine("Dog barks");
}
}
class Program
{
static void Main(string[] args)
{
Dog dog = new Dog();
dog.Speak();
dog.Bark();
}
}
Output:
8
12202040501079 Pushti Baldha
.NET Technology -202045604
5) Parms Parameter
Code:
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Sum(1, 2, 3));
Console.WriteLine(Sum(1, 2, 3, 4, 5));
}
static int Sum(params int[] numbers)
{
int sum = 0;
foreach (int number in numbers)
{
sum += number;
}
return sum;
}
}
Output
Code:
using System;
using System.Collections.Generic;
class Program
{
static int calculateSum(int x, int y)
{
return x + y;
}
public delegate int myDelegate(int num1, int num2);
Output:
9
12202040501079 Pushti Baldha
.NET Technology -202045604
Code:
using System;
class RefOutExample
{
public void Ref(ref int number)
{
number += 10;
}
public void Out(out int result)
{
result = 20;
}
static void Main()
{
RefOutExample example = new RefOutExample();
int refValue = 5;
example.Ref(ref refValue);
Console.WriteLine($"Value after ref: {refValue}");
int outValue;
example.Out(out outValue);
Console.WriteLine($"Value after out: {outValue}");
}
}
Output:
PRACTICAL 04
4) Demonstrate the use of Properties and Indexer.
Code:
using System;
namespace prac4
{
public class Employee
{
private string _empName = "Not known";
private int _salary = 0;
private static int _cnt;
public Employee()
{
_cnt += 1;
}
public string EmpName
{
get { return _empName; }
set { _empName = value; }
}
public int Salary
{
get { return _salary; }
set { _salary = value; }
}
public static int Counter
{
get { return _cnt; }
}
}
11
12202040501079 Pushti Baldha
.NET Technology -202045604
12
12202040501079 Pushti Baldha
.NET Technology -202045604
4.2) Indexing
Code:
using System;
class Program
{
obj[0] = "Pushti";
obj[1] = "Dev";
obj[2] = "Yogi";
13
12202040501079 Pushti Baldha
.NET Technology -202045604
PRACTICAL-05
Write a program for Arithmetic Calculator using Windows Application
Code:
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;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
namespace Practical_5._1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int num1, num2;
string option;
int result;
string total;
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
14
12202040501079 Pushti Baldha
.NET Technology -202045604
}
private void btn6_Click(object sender, EventArgs e)
{
Toaltext.Text = Toaltext.Text + "6";
}
private void button9_Click(object sender, EventArgs e)
{
Toaltext.Text = Toaltext.Text + "7";
}
private void button8_Click(object sender, EventArgs e)
{
Toaltext.Text = Toaltext.Text + "8";
}
private void button7_Click(object sender, EventArgs e)
{
Toaltext.Text = Toaltext.Text + "9";
}
private void btn0_Click(object sender, EventArgs e)
{
Toaltext.Text = Toaltext.Text + "0";
}
private void button15_Click(object sender, EventArgs e)
{
option = "+";
num1=int.Parse(Toaltext.Text);
Toaltext.Clear();
}
private void button14_Click(object sender, EventArgs e)
{
option = "-";
num1 = int.Parse(Toaltext.Text);
Toaltext.Clear();
}
private void button13_Click(object sender, EventArgs e)
{
option = "%";
num1 = int.Parse(Toaltext.Text);
Toaltext.Clear();
}
private void button12_Click(object sender, EventArgs e)
{
option = "*";
num1 = int.Parse(Toaltext.Text);
Toaltext.Clear();
}
private void button11_Click(object sender, EventArgs e)
{
option = "/";
num1 = int.Parse(Toaltext.Text);
Toaltext.Clear();
}
15
12202040501079 Pushti Baldha
.NET Technology -202045604
16
12202040501079 Pushti Baldha
.NET Technology -202045604
17
12202040501079 Pushti Baldha
.NET Technology -202045604
PRACTICAL-6
Implement Windows Form based application using controls like menus,
dialog and tool tip, dropdown, radio and selection button etc.
Form1.cs:
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 PRACTICAL6
{
public partial class Form1: Form
{
public Form1()
{
InitializeComponent();
toolTip1.SetToolTip(button1, "Click to submit your registration");
}
private void label1_Click(object sender, EventArgs e)
{ }
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{ }
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{ }
private void label3_Click(object sender, EventArgs e)
{ }
private void button1_Click(object sender, EventArgs e)
{
string name = textBox1.Text;
string email = textBox2.Text;
string gender = radioButton1.Checked ? "Male" : radioButton2.Checked ?
"Female" : "Not selected";
string dept = listBox1.SelectedItem != null ? listBox1.SelectedItem.ToString() :
"Not selected";
string year = comboBox1.SelectedItem != null ? comboBox1.SelectedItem.ToString() :
"Not selected";
label6.Text = "Name: " + name;
label7.Text = "Email: " + email;
label8.Text = "Gender: " + gender;
label9.Text = "Dept: " + dept;
18
12202040501079 Pushti Baldha
.NET Technology -202045604
Form2.cs:
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 PRACTICAL6
{
public partial class Form2: Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form1 form = new Form1();
form.Show();
}
}
}
Program.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PRACTICAL6
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
19
12202040501079 Pushti Baldha
.NET Technology -202045604
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form2());
}
}
}
Output:
20
12202040501079 Pushti Baldha
.NET Technology -202045604
Practical-7
Implement concepts of Inheritance, visual inheritance and Interface in
widows form application.
Code:
Form1.cs:
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 Practical7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
namespace Practical7
{
public partial class Form2 : Practical7.Form1
{
21
12202040501079 Pushti Baldha
.NET Technology -202045604
public Form2()
{
InitializeComponent();
}
}
public override void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Add Dervied button clicked");
}
22
12202040501079 Pushti Baldha
.NET Technology -202045604
23
12202040501079 Pushti Baldha
.NET Technology -202045604
PRACTICAL – 8
Use Dataset, Data Reader, XML Reader & Data Sources (SQL, Object & XML)
with Any Windows or Web Application.
Form1.cs:
using System;
using System.Data;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace MySQLDemoApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string connectionString
="server=localhost;user=root;database=tithi;password=cow_@bark;";
using (MySqlConnection conn = new MySqlConnection(connectionString))
{
try
{
conn.Open();
string query = "SELECT * FROM faculty";
MySqlDataAdapter adapter = new MySqlDataAdapter(query, conn);
DataTable dt = new DataTable();
adapter.Fill(dt);
dataGridView1.DataSource = dt;
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
// Optional: Handle cell click if needed
}
}
}
24
12202040501079 Pushti Baldha
.NET Technology -202045604
Form1.Design.cs:
namespace MySQLDemoApp
{
partial class Form1
{
private System.ComponentModel.IContainer components = null;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.DataGridView dataGridView1;
25
12202040501079 Pushti Baldha
.NET Technology -202045604
this.button1.TabIndex = 0;
this.button1.Text = "View Data";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// dataGridView1
//
this.dataGridView1.ColumnHeadersHeightSizeMode =
System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Location = new System.Drawing.Point(180, 50);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.RowHeadersWidth = 51;
this.dataGridView1.RowTemplate.Height = 24;
this.dataGridView1.Size = new System.Drawing.Size(400, 250);
this.dataGridView1.TabIndex = 1;
this.dataGridView1.CellContentClick += new
System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClic
k);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(650, 350);
this.Controls.Add(this.dataGridView1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "MySQL Data Viewer";
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
this.ResumeLayout(false);
}
}
}
In MySql :
26
12202040501079 Pushti Baldha
.NET Technology -202045604
Output:
27
12202040501079 Pushti Baldha