private void button1_Click(object sender, EventArgs e) { Delegate_Prod delObj = new Delegate_Prod(suma); Delegate_Prod delObj1 = new Delegate_Prod(resta); Delegate_Prod delObj2 = new Delegate_Prod(div); Delegate_Prod delObj3 = new Delegate_Prod(multi); Console.Write("Please Enter Values"); int v1 = Int32.Parse(this.textBox1.Text); int v2 = Int32.Parse(this.textBox2.Text); //use a delegate for processing double res = delObj(v1, v2); MessageBox.Show("Result :" + res); double res1 = delObj1(v1, v2); MessageBox.Show("Result :" + res1); double res2 = delObj2(v1, v2); MessageBox.Show("Result :" + res2); double res3 = delObj3(v1, v2); MessageBox.Show("Result :" + res3); }
static void Main(string[] args) { Delegate_Prod delObj = new Delegate_Prod(totalCast); Console.WriteLine("Total Cost of Car is: "); int v1 = int.Parse(Console.ReadLine()); Console.WriteLine("Service Charges On Car is :"); int v2 = int.Parse(Console.ReadLine()); double res = delObj(v1, v2); Console.WriteLine("Price of Car is : " + res); Console.ReadKey(); }
static void Main(string[] args) { Delegate_Prod exam = new Delegate_Prod(fn_Provalues); Console.Write("please enter the values: "); int v1 = Int32.Parse(Console.ReadLine()); Console.Write("and "); int v2 = Int32.Parse(Console.ReadLine()); double res = exam(v1, v2); Console.WriteLine("Result :" + res); Console.ReadLine(); }
static void Main(string[] args) { //inherit delegete and initialization with function fn_Prodvalues Delegate_Prod delObj = new Delegate_Prod(fn_Prodvalues); Console.Write("Please Enter Values :"); int v1 = Int32.Parse(Console.ReadLine()); int v2 = Int32.Parse(Console.ReadLine()); //initiali object delObj for output double res = delObj(v1, v2); Console.WriteLine("Result :{0}", res); Console.ReadLine(); }
static void Main(string[] args) { //Creating the Delegate Instance Delegate_Prod delObj = new Delegate_Prod(fn_Prodvalues); Console.Write("Please Enter Values"); int v1 = Int32.Parse(Console.ReadLine()); int v2 = Int32.Parse(Console.ReadLine()); //use a delegate for processing double res = delObj(v1, v2); Console.WriteLine("Result :" + res); Console.ReadLine(); }
public static void Main(string[] args) { Delegate_Prod delObj = new Delegate_Prod(fn_Prodvalues); Console.WriteLine("Please enter Values"); int v1 = Convert.ToInt32(Console.ReadLine()); Console.ReadKey(); Console.WriteLine("Please enter Values"); int v2 = Convert.ToInt32(Console.ReadLine()); Console.ReadKey(); double res = delObj(v1, v2); Console.WriteLine("Result " + res); Console.ReadLine(); }
static void Main(string[] args) { Program p = new Program(); p.addressExtensionMethod(); Example example = new Example(); example.Number = 5; // set { } Console.WriteLine(example.Number); // get { } Person per = new Person(); per.Name = "Jim"; // the set accessor is invoked here per.Age = 25; Console.WriteLine(per.Name); // the get accessor is invoked here Console.WriteLine(per.Age); // Intialize a new object. Customer cust1 = new Customer(4987.63, "Northwind", 90108); //Modify a property cust1.TotalPurchases += 499.99; Console.WriteLine(cust1.TotalPurchases + " " + cust1.Name); IDictionary <int, string> dict = new Dictionary <int, string>(); dict.Add(1, "What is your name?"); dict.Add(3, "What is your age?"); dict.Add(4, "Where do you live?"); dict.Add(2, "What are your hobbies?"); var items = dict.OrderBy(s => s.Key); foreach (var item in items) { Console.WriteLine(item.Key + " " + item.Value); } Transform t = Square; int result = t(3); Console.WriteLine(result); //the delegate instance is created and the function name is passed to the delegate instance //Creating the Delegate Instance Delegate_Prod delObj = new Delegate_Prod(fn_ProdValues); //use a delegate for processing //pass two values to the delegate //Here delegate object encapsulates the method functionalities and returns the result as we specified in the method. double res = delObj(5, 10); Console.WriteLine(res); List <int> l = new List <int> { 1, 2, 3, 4, 5 }; Dictionary <int, string> dict2 = new Dictionary <int, string>(); SortedList <int, string> sl = new SortedList <int, string>(); sl.Add(4, "dd"); sl.Add(3, "cc"); sl.Add(2, "bb"); sl.Add(1, "aa"); foreach (var item in sl) { Console.WriteLine(item.Key); } SortedList <string, string> sl1 = new SortedList <string, string>(); sl1.Add("ddd", "ddd"); sl1.Add("aaa", "aaa"); foreach (var item in sl1) { Console.WriteLine(item.Key); } List <int> list = new List <int> { 1, 2, 3, 9, 10, 11, 12 }; //The list gets populated with values List <int> matches = list.FindAll(val => val != 9); foreach (var match in matches) { Console.WriteLine(match); } p.GetWordCountExtensionMethod(); string test = "this is some text without a capital letter"; Console.WriteLine(test + ": " + test.HasCapitals()); test = "This is some text WITH a capital letter"; Console.WriteLine(test + ": " + test.HasCapitals()); Func <string, string> toUpper = s => s.ToUpper(); string upperText = toUpper("Hello world!"); Console.WriteLine(upperText); Func <DateTime, int> month = d => d.Month; int m = month(new DateTime(2011, 3, 14)); Console.WriteLine(m); Console.ReadLine(); }