0% found this document useful (0 votes)
5 views

c# programs

Uploaded by

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

c# programs

Uploaded by

aakash181j
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

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 _1darray
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
var x= new string[5];
for(int i =0; i<x.Length; i++)
{
MessageBox.Show("the default value of integer is: " + x[i]);
}
}
}
}

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 abstraction
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

class Test
{
int x, y;
public void Read(int a, int b)
{
x = a;
y = b;
}
public void print() {
int k = x + y;
MessageBox.Show("the value is: " + k.ToString());
}

}
private void button1_Click(object sender, EventArgs e)
{
Test t = new Test();
MessageBox.Show(t.GetHashCode().ToString());
MessageBox.Show(t.GetType().Name);
t.Read(20,30);
t.print();
Test t1 = new Test();
t1.print();
Test t2 = t;
t2.print();
}
}
}

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 boxing
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
int i = 1000, j=2000;
if (i > j)
{
this.BackColor = Color.GreenYellow;

}
else
{
this.BackColor = Color.Red;
}
}
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace c__styleoftypecaset
{
internal class Program
{
static void Main(string[] args)
{
Console.Write("hello world");
Console.WriteLine("hello planet");
Console.WriteLine("DateTime: "+"\n"+DateTime.Now.ToString());
Console.Read();
}
}
}

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

namespace C__typecaste2
{
internal class Program
{
static void Main(string[] args)
{
int i = 100;

byte s = (byte)i;
Console.WriteLine("the value of s is: " + s);
Console.Read();

}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace constructor_and_destructor
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
class Test
{
public Test()
{
MessageBox.Show("from constructor");
}
~Test()
{
MessageBox.Show("from destructor");
}
}
private void button1_Click(object sender, EventArgs e)
{
Test t= new Test();
}
}
}

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 dowhile
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
int[] ids = new int[] { 6, 7, 8,10 };
int sum = 0;
int i = 0;
do
{
sum += ids[i];
i++;

}
while (i <= 2);
MessageBox.Show("the sum is: " + sum);
}
}
}

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 encap
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
class Emp
{
int sal = 5000;
public void increment(int sal)
{
this.sal = this.sal + sal;
}

public void print()


{
MessageBox.Show("the total salary is:" + sal);
}
}
private void button1_Click(object sender, EventArgs e)
{
Emp e1 = new Emp();
e1.increment(3000);
e1.print();
}
}
}

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 enums
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
enum test
{
A,
B = 10,
C
}
private void button1_Click(object sender, EventArgs e)
{
int i, j, k;
i = (int)test.A;
j = (int)test.B;
k = (int)test.C;
MessageBox.Show(i + "\n" + j + "\n" + k);

}
}
}

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 @foreach
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
string[] days = {
"sunday",
"monday",
"tuesday",
"wednesday",
"thursday",
"friday",
"saturday",
"sunday"};
foreach (var item in days)
{
MessageBox.Show("the days is: "+ item);
}
}
}
}

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 forloop
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
string s = "";
for(int i = 65; i <= 90; i++)
{
char c = (char)i;
s=s+"\n"+c;
}
MessageBox.Show(s);
}
}
}

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 forloop1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
int x = 50;
for (int i =0; i<= 15; i++)
{
TextBox t= new TextBox();
t.Location = new Point(300,x);
this.Controls.Add(t);
x = x + 50;
}
}
private void Form1_Load(object sender, EventArgs e)
{

}
}
}

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 function_overloading
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

class Test
{
public void show(float x)
{
MessageBox.Show("from float:" + x.ToString());
}
public void show(double x)
{
MessageBox.Show("from double:" + x.ToString());
}
public void show(decimal x)
{
MessageBox.Show("from decimal:" + x.ToString());
}
public void show(int x)
{
MessageBox.Show("from integer:"+x.ToString());
}
public void show(string x)
{
MessageBox.Show("from string:" + x.ToString());
}
private void button1_Click(object sender, EventArgs e)
{
Test t = new Test();
t.show(4.5m);
t.show(4.5d);
t.show(4.5f);
t.show(1000);
t.show("hello");
}
}

}
}

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 inheritance
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
class Employee
{
private int EmpNo = 101;
private string EmpName = "venkat";
private string Department = "LDS";
private string designation = "CM";
private string Address = "mylapore";
private string Email = "[email protected]";
protected int salary = 5000;

public void print()


{
MessageBox.Show("the empno is:" + EmpNo + "\n" + "the EmpName is:"+EmpName+
"\n"
+ "the Department is:" + Department + "\n" + "the designation is:" + designation +
"\n"
+ "the Address is:" + Address + "\n" + "the Email is:" + Email + "\n" + "the salary
is:" + salary + "\n");
}
}
class Bonus : Employee
{
private int b, ts;
public void calculate(int x)
{
b = x;
print();
ts = salary + b;
MessageBox.Show("The Total Salary is:" + ts);
}
}
private void button1_Click(object sender, EventArgs e)
{
DialogResult dr;
dr=MessageBox.Show("Are you GOING to GIVE
BONUS","NOVAC",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
if(dr==DialogResult.Yes)
{
Bonus b = new Bonus();
b.calculate(3000);

}
else
{
Employee emp = new Employee();
emp.print();
}
}
}
}

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 jaggedarray
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
int[][] x = new int[3][];
x[0] = new int[] { 1, 3, 5 };
x[1] = new int[] { 8, 5, 6, 7 };
x[2] = new int[] { 8, 9 };
string s = "";
for(int i = 0;i<x.Length;i++)
{
for (int j = 0; j < x[i].Length; j++)
{
s = s + x[i][j]+" ";
}
s=s + "\n";
}
MessageBox.Show(s);
}
}
}

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 multidimarray
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
var x = new int[,] { { 1, 2, 3 } , { 4, 5, 7 } };
string s = "";
for(int r = 0; r < x.GetLength(0); r++)
{
for (int c = 0; c < x.GetLength(1); c++)
{
s = s + "" + x[r,c].ToString();
}
s += "\n";
}
MessageBox.Show("the array:"+s);
}

}
}

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 operator_overloading
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
class Test
{
private string s;
public Test(string a) {
s = a;
}
public static string operator +(Test x, Test y)
{
string abc =x.s + y.s;
return abc;
}
}
private void button1_Click(object sender, EventArgs e)
{
Test t1 =new Test("hello");
Test t2 =new Test("hello WORLD");
string t3 = t1 + t2;
MessageBox.Show(t3.ToString());
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace parsing
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine(int.MinValue.ToString());
Console.WriteLine(int.MaxValue.ToString());
Console.WriteLine(DateTime.MinValue.ToString());
Console.WriteLine(DateTime.MaxValue.ToString());
Console.WriteLine(Decimal.MinValue.ToString());
Console.WriteLine(Decimal.MaxValue.ToString());
Console.ReadLine();
}
}
}

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 @static
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
class Test
{
private static int i;//instance variable
private static int s;//static variable

static Test()
{
s = 0;
i = 0;

//by default i = 0;
}
public Test()
{
i = i + 1;
s = s + 1;
MessageBox.Show(i.ToString() + "\n" + s.ToString());
}
private void button1_Click(object sender, EventArgs e)
{
Test t1 = new Test();
Test t2 = new Test();
Test t3 = new Test();
}
}

private void button2_Click(object sender, EventArgs e)


{
Test t1 = new Test();
Test t2 = new Test();
Test t3 = new Test();
}
}
}

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 statickeyword1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
static class test
{
public static void show(string s)
{
MessageBox.Show(s);
}
}
private void button1_Click(object sender, EventArgs e)
{
test.show("hello good morning");
}
}
}

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

namespace typecast3
{
internal class Program
{
static void Main(string[] args)
{
char c = '?';
int i = Convert.ToInt32(c);
Console.WriteLine(i);
//int i = 66;
//char c =Convert.ToChar(i);
//Console.WriteLine("the value of c is: " + c);
Console.ReadLine();

}
}
}
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 unboxing
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void label1_Click(object sender, EventArgs e)


{

private void textBox1_TextChanged(object sender, EventArgs e)


{

private void button1_Click(object sender, EventArgs e)


{
int i = int.Parse(textBox1.Text);
switch (i)
{
case 1:
this.BackColor = Color.GreenYellow;
break;
case 2:
this.BackColor = Color.AliceBlue;
break;
case 3:
ColorDialog cd = new ColorDialog();
cd.ShowDialog();
this.BackColor = cd.Color;
break;
case 4:
Application.Exit();
break;
default:
MessageBox.Show("PLEASE ENTER VALUES 1,2 3 AND 4 ONLY");
break;
}
}
}
}
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 whileloop
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
int i = 0;
while(i <= 20)
{
MessageBox.Show("while statement: " + i);
i++;
i++;
}
}
}
}

You might also like