using System;
namespace constructorExample{
classconstructor{
public constructor(){
Console.WriteLine("Default Constructor Called");
}
static void Main(string[] args){
constructor c=new constructor();
}
}
}
using System;
namespace copyExample{
class copy{
private string month;
private int year;
public copy(copy c){
month=c.month;
year=c.year;
}
public copy(string month,int year){
this.month=month;
this.year=year;
}
public string De{
get{
return "Month is"+ month.ToString() + "nyear is" +year.ToString();
}
}
public static void Main(string[] args){
copy c1=new copy("june", 2022);
copy c2=new copy(c1);
Console.WriteLine(c2.De);
Console.ReadLine();
}
}
}
2.
using System;
namespace eventHandling
{
//Step1 Create delegate object
public delegate void MyHandler1(object sender, MyEventArgs e);
public delegate void MyHandler2(object sender, MyEventArgs e);
//Step 2 Create event handler methods
class A
{
public const string m_id = "Class A";
public void OnHandler1(object sender, MyEventArgs e)
{
Console.WriteLine("I am in OnHandler1 and MyEventArgs is {0}", e.m_id);
}
public void OnHandler2(object sender, MyEventArgs e)
{
Console.WriteLine("I am in OnHandler2 and MyEventArgs is {0}", e.m_id);
}
//Step 3 create delegates, plug in the handler and register with the object that will fire
the events
public A(B b)
{
MyHandler1 d1 = new MyHandler1(OnHandler1);
MyHandler2 d2 = new MyHandler2(OnHandler2);
b.Event1 += d1;
b.Event2 += d2;
}
}
//Step 4 Calls the encapsulated methods through the delegates (fires events)
class B
{
public event MyHandler1 Event1;
public event MyHandler2 Event2;
public void FireEvent1(MyEventArgs e)
{
if (Event1 != null)
{
Event1(this, e);
}
}
public void FireEvent2(MyEventArgs e)
{
if (Event2 != null)
{
Event2(this, e);
}
}
}
public class MyEventArgs : EventArgs
{
public string m_id;
}
public class Driver
{
public static void Main()
{
B b = new B();
A a = new A(b);
MyEventArgs e1 = new MyEventArgs();
MyEventArgs e2 = new MyEventArgs();
e1.m_id = "Event args for event 1";
e2.m_id = "Event args for event 2";
3.
b.FireEvent1(e1);
b.FireEvent2(e2);
}
}
}
using System;
namespace parameterizedConstructor{
classpara{
string name;
int id;
public para(string name,int id){
this.name=name;
this.id=id;
}
static void Main(string[] args){
para p=new para("sanika",1);
Console.WriteLine("name is "+p.name+"id is"+p.id);
}
}}
using System;
namespace privateExample{
class priconstruct{
private priconstruct(){
}
public static int a;
public static int count(){
return ++a;
}
public static void Main(string[] args){
priconstruct.a=100;
priconstruct.count();
Console.WriteLine(priconstruct.a);
priconstruct.count();
Console.WriteLine(priconstruct.a);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
4.
namespace copyexample
{
class copy
{
privatestring month;
private int year;
public copy(copy c)
{
month = c.month;
year = c.year;
}
public copy(string month, int year)
{
this.month = month;
this.year = year;
}
public string De
{
get
{
return "Month is" + month.ToString() + "nyear is" + year.ToString();
}
}
public static void Main(string[] args)
{
copy c1 = new copy("june", 2022);
copy c2 = new copy(c1);
Console.WriteLine(c2.De);
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace delegateExample
{
public delegate void Calculation(int a, int b);
internal class Program
{
public static void addition(int a ,int b)
{
Console.WriteLine(a + b);
5.
}
public static voidsub(int a, int b)
{
Console.WriteLine(a - b);
}
public static void multi(int a, int b)
{
Console.WriteLine(a *b);
}
public static void div(int a, int b)
{
Console.WriteLine(a / b);
}
static void Main(string[] args)
{
Calculation ob = new Calculation(Program.addition);
ob.Invoke(20, 40);
Calculation ob1 = new Calculation(Program.sub);
ob1.Invoke(20, 40);
Calculation ob2 = new Calculation(Program.multi);
ob2.Invoke(20, 40);
Calculation ob3 = new Calculation(Program.div);
ob3.Invoke(20, 40);
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace fileHandling
{
public class Program
{
public class fileExample
{
public void Data()
{
StreamWriter sw = new StreamWriter(@"D:volumemyFile.txt");
Console.WriteLine("Enter the text you want to write to file");
string str = Console.ReadLine();
sw.WriteLine(str);
sw.Flush();
sw.Close();
}
6.
}
static void Main(string[]args)
{
fileExample p = new fileExample();
p.Data();
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace inheritance_example
{
public class Program
{
class person{
public void show()
{
Console.WriteLine("This Is Base Class");
}
}
interface employee
{
void show2();
}
interface employee1
{
void show3();
}
class derived1: person,employee,employee1
{
public void show2()
{
Console.WriteLine("This is interfeace");
}
public void show3()
{
Console.WriteLine("This is interfeace2");
}
}
static void Main(string[] args)
{
derived1 d1 = new derived1();
// d1.show3();
d1.show2();
7.
d1.show();
d1.show3();
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
usingSystem.Linq;
using System.Text;
using System.Threading.Tasks;
namespace multdimentional_arrays
{
public class Class1
{
static void Main(string[] args)
{
int[,] arr = new int[3, 4]
{
{1,2,3,4},
{1,2,3,4 },
{1,2,3,4 }
};
for(int i = 0; i < arr.GetLength(0); i++)
{
for(int j = 0; j <arr.GetLength(1); j++)
{
Console.Write(arr[i, j]);
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace multidimensional
{
8.
public class Class1
{
staticvoid Main(string[] args)
{
int[][] arr = new int[3][];
arr[0] =new[] { 1,3,4,5,5,67,7};
arr[1] =new[] { 2,4,5,6,7};
arr[2] =new[] { 12,34,5};
for (int i = 0; i < arr.GetLength(0); i++)
{
for (int j = 0; j < arr[i].Length; j++)
{
Console.Write(arr[i][j]+" ");
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace operator_overloading
{
internal class Newclass
{
public string str;
public int num;
public static Newclass operator +(Newclass obj1, Newclass obj2)
{
Newclass obj3 = new Newclass();
obj3.str = obj1.str + obj2.str;
obj3.num = obj1.num + obj2.num;
return obj3;
}
static void Main(string[] args)
{
Newclass obj1= new Newclass();
obj1.str = "sanika";
obj1.num = 2;
Newclass obj2 = new Newclass();
9.
obj2.str = "patil";
obj2.num= 30;
Newclass obj3 = new Newclass();
obj3 = obj1 + obj2;
Console.WriteLine(obj3.str );
Console.WriteLine(obj3.num);
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace readingFile
{
public class Program
{
public class ReadFile
{
public void ReadData()
{
StreamReader sr = new StreamReader("D:volumemyFile.txt");
Console.WriteLine("data from file is :");
sr.BaseStream.Seek(0, SeekOrigin.Begin);
string str = sr.ReadLine();
while (str != null)
{
Console.WriteLine(str);
str = sr.ReadLine();
}
Console.ReadLine();
sr.Close();
}
}
static void Main(string[] args)
{
ReadFile file = new ReadFile();
file.ReadData();
Console.WriteLine("Data Read successful");
}
}
}
10.
using System;
using System.Collections.Generic;
usingSystem.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace register
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source =(localdb)MSSQLLocalDB; Initial
Catalog = registerData; Integrated Security = True");
SqlCommand cmd = new SqlCommand(@"INSERT INTO[dbo].[registerr]
([firstname],
[lastname],
[address],
[gender],
[email],
[phone],
[username],
[password])
VALUES
('" + textBox1.Text + "', '" + textBox2.Text + "', '" + textBox3.Text + "', '" +
comboBox1.SelectedItem.ToString() + "', '" + textBox4.Text + "', '" + textBox5.Text + "', '" +
textBox6.Text + "', '" + textBox7.Text + "')", conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("Register Successfully");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
11.
namespace register
{
internal staticclass Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}