using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Bookstore;
using System.Threading;
namespace ConsoleApplication1
{
//public class DelegateDemo4
//{
// delegate Guid DoComplexLogic();
// public static void Main(string[] args)
// {
// DoComplexLogic docomplexLogic = MyComplexLogic;
// docomplexLogic.BeginInvoke(new AsyncCallback(CallBackMyComplexTask), docomplexLogic);
// Console.WriteLine("New task is started!");
// Console.Read();
// }
// public static void CallBackMyComplexTask(IAsyncResult asyncResult)
// DoComplexLogic doComplexLogic = (DoComplexLogic)asyncResult.AsyncState;
// Guid newGuid = doComplexLogic.EndInvoke(asyncResult);
// Console.WriteLine(newGuid);
// public static Guid MyComplexLogic()
// Thread.Sleep(3000);
// return Guid.NewGuid();
//}
//--------------------------------------------------------
//delegate int NumberChanger(int n);
//class TestDelegate
// static int num = 10;
// public static int AddNum(int p)
// num += p;
// return num;
// public static int MultNum(int q)
// num *= q;
// public static int getNum()
// static void Main(string[] args)
// //create delegate instances
// NumberChanger nc;
// NumberChanger nc1 = new NumberChanger(AddNum);
// NumberChanger nc2 = new NumberChanger(MultNum);
// nc = nc1;
// nc += nc2;
// //calling multicast
// nc(5);
// Console.WriteLine("Value of Num: {0}", getNum());
// Console.ReadKey();
//------------------------------------------------------
// public delegate void NumberChanger(int n);
// public event NumberChanger nce;
// public void getnumberbyevent(int w)
// if (nce != null)
// nce(w);
// public static void AddNum(int p)
// Console.WriteLine("Named Method: {0}", num);
// public static void MultNum(int q)
// //create delegate instances using anonymous method
// NumberChanger nc = delegate(int x)
// Console.WriteLine("Anonymous Method: {0}", x);
// };
// //calling the delegate using the anonymous method
// nc(10);
// //instantiating the delegate using the named methods
// nc = new NumberChanger(AddNum);
// //calling the delegate using the named methods
// //instantiating the delegate using another named methods
// nc = new NumberChanger(MultNum);
// nc(2);
// TestDelegate obj = new TestDelegate();
// obj.nce += delegate(int w)
// Console.WriteLine("my event message is :{0}", w);
// obj.getnumberbyevent(50);
//----------------------------------------------------
//public class MyClass
// public delegate void MyDelegate(string message);
// public event MyDelegate MyEvent;
// public void RaiseMyEvent(string msg)
// if (MyEvent != null)
// MyEvent(msg);
//class Caller
// MyClass myClass1 = new MyClass();
// //Register event handler as anonymous method.
// myClass1.MyEvent += delegate
// Console.WriteLine("we don't make use of your message in the first handler");
// //here we make use of the incoming arguments.
// myClass1.MyEvent += delegate(string message)
// Console.WriteLine("your message is: {0}", message);
// //the final bracket of the anonymous method must be terminated by a semicolon.
// Console.WriteLine("Enter Your Message");
// string msg = Console.ReadLine();
// //here is we will raise the event.
// myClass1.RaiseMyEvent(msg);
// Console.ReadLine();
//--------------------------
//class PriceTotaller
// int countBooks = 0;
// decimal priceBooks = 0.0m;
// internal void AddBookToTotal(Book book)
// countBooks += 1;
// priceBooks += book.Price;
// internal decimal AveragePrice()
// return priceBooks / countBooks;
//// Class to test the book database:
//class Test
// // Print the title of the book.
// static void PrintTitle(Book b)
// Console.WriteLine(" {0}", b.Title);
// // Execution starts here.
// static void Main()
// BookDB bookDB = new BookDB();
// // Initialize the database with some books:
// AddBooks(bookDB);
// // Print all the titles of paperbacks:
// Console.WriteLine("Paperback Book Titles:");
// // Create a new delegate object associated with the static
// // method Test.PrintTitle:
// bookDB.ProcessPaperbackBooks(new ProcessBookDelegate(PrintTitle));
// // Get the average price of a paperback by using
// // a PriceTotaller object:
// PriceTotaller totaller = new PriceTotaller();
// // Create a new delegate object associated with the nonstatic
// // method AddBookToTotal on the object totaller:
// bookDB.ProcessPaperbackBooks(new ProcessBookDelegate(totaller.AddBookToTotal));
// Console.WriteLine("Average Paperback Book Price: ${0:#.##}",
// totaller.AveragePrice());
// // Initialize the book database with some test books:
// static void AddBooks(BookDB bookDB)
// bookDB.AddBook("The C Programming Language",
// "Brian W. Kernighan and Dennis M. Ritchie", 19.95m, true);
// bookDB.AddBook("The Unicode Standard 2.0",
// "The Unicode Consortium", 39.95m, true);
// bookDB.AddBook("The MS-DOS Encyclopedia",
// "Ray Duncan", 129.95m, false);
// bookDB.AddBook("Dogbert's Clues for the Clueless",
// "Scott Adams", 12.00m, true);
// -----------------------------------------------
// class Person
// public string Name { get; set; }
// public int Age { get; set; }
//class Program
// //Our delegate
// public delegate bool FilterDelegate(Person p);
// //Create 4 Person objects
// Person p1 = new Person() { Name = "John", Age = 41 };
// Person p2 = new Person() { Name = "Jane", Age = 69 };
// Person p3 = new Person() { Name = "Jake", Age = 12 };
// Person p4 = new Person() { Name = "Jessie", Age = 25 };
// //Create a list of Person objects and fill it
// List<Person> people = new List<Person>() { p1, p2, p3, p4 };
// DisplayPeople("Children:", people, IsChild);
// DisplayPeople("Adults:", people, IsAdult);
// DisplayPeople("Seniors:", people, IsSenior);
// static void DisplayPeople(string title, List<Person> people, FilterDelegate filter)
// Console.WriteLine(title);
// foreach (Person p in people)
// if (filter(p))
// Console.WriteLine("{0}, {1} years old", p.Name, p.Age);
// Console.Write("\n\n");
// //==========FILTERS===================
// static bool IsChild(Person p)
// return p.Age <= 18;
// static bool IsAdult(Person p)
// return p.Age >= 18;
// static bool IsSenior(Person p)
// return p.Age >= 65;
//------------------------------
//delegate T numbermanipulate<T>(T num);
// static int number = 10;
// public static int addnumber(int n)
// number = number + n;
// return number;
// public static int multinumber(int q)
// number = number * q;
// public static int getvalues()
// Console.WriteLine("enter two values");
// int k = Convert.ToInt32(Console.ReadLine());
// int m = Convert.ToInt32(Console.ReadLine());
// //create delegates instance
// numbermanipulate<int> nm = new numbermanipulate<int>(addnumber);
// nm(k);
// Console.WriteLine("addnumber values" + getvalues());
// numbermanipulate<int> nm1 = new numbermanipulate<int>(multinumber);
// nm1(m);
// Console.WriteLine("multi values" + getvalues());
// ------------------------------------------------------------------
}