Vous êtes sur la page 1sur 11

1.

2> put 2 textbox on form first text box ask entry value 2nd text box ask end v alue,display in 3rd box 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 WindowsFormsApplication1 { public partial class Form1 : Form { public Form1(){ InitializeComponent();} } private void button1_Click_1(object sender, EventArgs e) { int a = Convert.ToInt32(textBox1.Text); int b = Convert.ToInt32(textBox2.Text); int sum = 0; for (int i = a; i <= b; i++) { sum = sum + i; } textBox3.Text = Convert.ToString(sum); } } } .3 > console appln which will demonstrate the array and list using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { String[] s = new string[5]; s[0] = "mebin"; s[1] = "ebin"; s[2] = "bin"; s[3] = "in"; s[4] = "n"; Console.WriteLine("elements of array are"); foreach (String s1 in s) { Console.WriteLine(s1); } ArrayList a = new ArrayList(); a.Add("c"); a.Add("c++"); a.Add("java"); a.Add("perl"); Console.WriteLine("No of elements are " + a.Count + " and elements o f arraylist are = "); foreach (string s11 in a) {

Console.WriteLine(s11); } Console.Read(); } } } 3.4 > console appn display prime number using using using using System; System.Collections.Generic; System.Linq; System.Text;

namespace UserDefined { class primeException : Exception { private int a; private string str; public primeException(String s) { str = s; } public void dispException() { Console.WriteLine("prime number exception" + str); } } class prime { private int b; private Boolean Flag = false; public void shownum(int a) { int cnt = 0; int b = a; for (int i = 1; i < a; i++) { if (a % i == 0) cnt++; } if (cnt == 1) { Console.WriteLine("the number "+ b +" is a prime number"); } else Console.WriteLine("the number "+b+" is not a prime number"); } } class program { static void Main(string[] args) { prime p = new prime(); p.shownum(7); Console.Read();

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

namespace UserDefined { class primeException : Exception { private int a; private string str; public primeException(String s) { str = s; Console.WriteLine("prime number exception "); Console.WriteLine(str); } public void dispException() { Console.WriteLine("prime number exception" + str); } } class prime { private int b; private Boolean Flag = false; public void shownum(int a) { int cnt = 0; int b = a; for (int i = 1; i < a; i++) { if (a % i == 0) cnt++; } if (cnt == 1) { throw new primeException("the number is a prime number"); } else Console.WriteLine("the number " + b + " is not a prime number"); } } class program { static void Main(string[] args) { prime p = new prime(); try { p.shownum(6);

} catch(Exception ez) { } Console.Read(); } } } 4.5 > method overloading using using using using System; System.Collections.Generic; System.Linq; System.Text;

namespace ConsoleApplication1 { class sea { public Boolean search(string[] data, string etc) { Boolean flag = false; for(int i=0;i<data.Length;i++) { if(etc.Equals(data[i])) { flag=true; break; } } return flag; } public Boolean search(int[] data, int etc) { Boolean flag = false; for (int i = 0; i < data.Length; i++) { if (data[i] == etc) { flag = true; break; } } return flag; } } class program { static void Main(string[] args) { string[] data={"a","b","c","d","e","f"}; string etc="b"; sea s = new sea(); bool result = s.search(data,etc); int[] data1 = {1,2,3,4,5};

int etc1=3; bool result2 = s.search(data1,etc1); if(result) { Console.WriteLine("string element } else { Console.WriteLine("string element " } if(result2) { Console.WriteLine("integer element } else { Console.WriteLine("integer element } Console.Read(); } } }

" + etc + " found");

+ etc + " not found");

"+ etc1 + " found");

"+ etc1 + " not found");

5.6 > program will hav account class and demonstrate desired output on console using using using using System; System.Collections.Generic; System.Linq; System.Text;

namespace accountex { class account { private int accno; private string ac_name; private double bal; public void withdraw(int amt) { bal = bal - amt; } public void deposit(int amt) { bal = bal + amt; } public account(int i, string nm, double amt) { accno = i; ac_name = nm; bal = amt; } public void disp() { Console.WriteLine(accno); Console.WriteLine(ac_name); Console.WriteLine(bal); } } class program {

static void Main(String[] args) { int ac=Convert.ToInt32(Console.ReadLine()); String s=Console.ReadLine(); Double t=Convert.ToDouble(Console.ReadLine()); account c = new account(ac,s,t); c.disp(); c.deposit(10000); c.disp(); c.withdraw(1000); c.disp(); Console.Read(); } } } 6.7 > vehicle class method drive having common function and navigation hav funct ion for each class using using using using System; System.Collections.Generic; System.Linq; System.Text;

namespace AbstractEx { abstract class vehicle { public void drive() { Console.WriteLine("This is drive method"); } public abstract void navigation(); } class bullocart:vehicle { public override void navigation() { Console.WriteLine("this is bullocart navigation"); } } class bike:vehicle { public override void navigation() { Console.WriteLine("this is bike navigation"); } } class car:vehicle { public override void navigation() { Console.WriteLine("this is car navigation"); } } class program { static void Main(string[] args) { bullocart b= new bullocart();

b.drive(); b.navigation(); bike bk = new bike(); bk.drive(); bk.navigation(); car c = new car(); c.drive(); c.navigation(); Console.Read(); } } } 7.14 > add treeview 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 WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { //TreeNode node; TreeNode node = new TreeNode("fruits"); //node = treefood.Nodes.Add("fruits"); node.Nodes.Add("Apple"); node.Nodes.Add("peach"); TreeNode node1 = new TreeNode("fruits"); //node = TreeFood.Nodes.Add("vegitable"); node1.Nodes.Add("tomato"); node1.Nodes.Add("potato"); } private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { if (e.Action == TreeViewAction.ByMouse) { MessageBox.Show(e.Node.FullPath); } } } } 8.15 > window appn to demonstrate list navigation using list box using using using using using System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing;

using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { List<string> lst = new List<string>(); foreach (string s in listBox1.SelectedItems) lst.Add(s); foreach(string s in lst) { listBox2.Items.Add(s); listBox1.Items.Remove(s); } } private void button2_Click(object sender, EventArgs e) { List<string> lst1 = new List<string>(); foreach (string s in listBox2.SelectedItems) lst1.Add(s); foreach (string s in lst1) { listBox1.Items.Add(s); listBox2.Items.Remove(s); } } } } using System; using System.Collections; class Program { static void Main() { Hashtable hashtable = new Hashtable(); hashtable[1] = "One"; hashtable[2] = "Two"; hashtable[13] = "Thirteen"; foreach (DictionaryEntry entry in hashtable) { Console.WriteLine("{0}, {1}", entry.Key, entry.Value); } Console.Read(); } } this code is not working

using using using using using using using using using using

System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Windows.Forms; System.Data.SqlClient; System.Data.OleDb;

namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { SqlConnection scan; SqlCommand scant; SqlDataReader str; scan = new SqlConnection(); //OleDbConnection conn = new OleDbConnection(); //conn.ConnectionString = @"Provider=Microsoft.JET.OLEDB.4.0;Data So urce=C:\Employee.mdb;Persist Security Info=False;"; //scan = new SqlConnection(); scan.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Sourc e=C:\Employee.mdb"; //scant = new SqlCommand(); //scant.SqlCommandtext = "select * from emp"; string CommandText = "SELECT * FROM EMPREC"; scant = new SqlCommand(CommandText); scan.Open(); str = scant.ExecuteReader(); if (str.Read()) { textBox1.Text = str[0].ToString(); textBox2.Text = str[1].ToString(); textBox3.Text = str[2].ToString(); textBox4.Text = str[3].ToString(); textBox5.Text = str[4].ToString(); } str.Close(); scan.Close(); } } } using using using using using System; System.Collections.Generic; System.Linq; System.Text; System.Collections;

namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Hashtable bt = new Hashtable(); bt.Add("text", "notepad"); bt.Add("image", "paint"); bt.Add("jpg", "paint.exe"); bt.Add("rtf", "wordpad"); try { bt.Add("txt","winword"); } catch{ Console.WriteLine("an element with key= \" text \" already exi st"); } Console.WriteLine("for key \" rtf \" ,value =[0] ", bt["rtf"] ); bt["rtf"]="wordpad"; Console.WriteLine("for key \" rtf \" ,value =[0] ", bt["rtf"] ); bt["doc"]="winword"; if(!bt.ContainsKey("rtf")) { bt.Add("htm","hypertext"); Console.WriteLine("value added for key = \" htm \" [0]" ,bt["htm "]); Console.WriteLine(); foreach(DictionaryEntry de in bt) { Console.WriteLine("key=[0];value=[1]",de.Key,de.Value); } Console.WriteLine(); /*foreach(string s in Value[01]) { Console.WriteLine("value=[0]",s); } a.Keycall=bt.Keys; Console.WriteLine(); foreach(string s in a.Keycall) { Console.WriteLine("key=[0]",s); } Console.WriteLine("\nremove(\"htm\")"); bt.Remove("htm"); if(!bt.ContainsKey("htm")) { Console.WriteLine("key \"htm\" is not available"); }*/ } Console.Read(); } } }

using using using using

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

namespace ConsoleApplication1 { interface vehicle { void drive(); void navigate(); } class car : vehicle { public void drive() {//code } public void navigate() {//code } } class bike : vehicle { public void drive() {//code } public void navigate() {//code } } class bullockcart : vehicle { public void drive() {//code } public void navigate() {//code } } class Program { static void Main(string[] args) { car c = new car(); c.drive(); c.navigate(); bike b = new bike(); b.drive(); b.navigate(); bullockcart bu = new bullockcart(); bu.drive(); bu.navigate(); Console.Read(); } } }

Vous aimerez peut-être aussi