static void Main(string[] args) { CalDelegate <int> Plus = new CalDelegate <int>(Add); CalDelegate <double> Minus = Sub; Calc(11, 11, Plus); Calc(5.11, 1.18, Minus); }
static void Main(string[] args) { //1 - Create a class of Student(id, name) //Use //1- List //2- ArrayList //Fill them with 5 students. //Navigate through them and print the name of students in the Console Student.StudentList(); Student.StudentArrayList(); //2 - Create a Generic Class name it 'MyGenericClass' //define generic method that prints the value of the parameter in the console. //call it with String and int values int iValue = 123; string sValue = "456xyz"; MyGenericClass.MyGenericMethod <int>(iValue); MyGenericClass.MyGenericMethod <string>(sValue); //3 - Create a hashtable and add 5 dictionaries of(key, value) optional //iterate through them and print them out in the console. Hashtable ht = new Hashtable(); ht.Add("E", "e"); ht.Add("A", "a"); ht.Add("C", "c"); ht.Add("B", "b"); ht.Add("D", "d"); foreach (DictionaryEntry de in ht) { Console.WriteLine("Key : {0} ; Value : {1}.", de.Key, de.Value); } //4 - Create a Constraint Generic Class name it 'MyconstraintGenericClass' //that limits the caller to use only referenced type int vaulueType = 123; MyconstraintGenericClass.MyConstraintGenericMethod <int>(vaulueType); //String is reference type do not match with constraint string referenceType = "456xyz"; //MyconstraintGenericClass.MyConstraintGenericMethod<string>(referenceType); //6 - Use Delegate in a class to calculate area, circumference, biggest side, ... CalDelegate circleAreaDL = new CalDelegate(Calculator.CircleArea); CalDelegate circumferenceDL = new CalDelegate(Calculator.Circumference); int r = 5; Console.WriteLine("Area of r={0} Circle : {1}", r, circleAreaDL(r)); Console.WriteLine("Circumference of r={0} Circle : {1}", r, circumferenceDL(r)); CalDelegate1 longestEdgeDL = new CalDelegate1(Calculator.LongestEdge); int l1 = 3; int l2 = 4; Console.WriteLine("Longest edge of right-angled triangle with L1={0} L2={1}: {2}", l1, l2, longestEdgeDL(l1, l2)); }
static void Main(string[] args) { CalDelegate d = new CalDelegate(Add); d(10, 5); d = Sub; d(10, 5); d = Mul; d(10, 5); d = Div; d(10, 5); }
static void Main(string[] args) { //CalDelegate Plus = new CalDelegate(Add); //CalDelegate Minus = new CalDelegate(Sub); // 위도 가능하지만 간단하게도 가능 CalDelegate Plus = Add; CalDelegate Minus = Sub; Calc(11, 22, Plus); Calc(22, 11, Minus); // 콜백 ? A B C 관계에서 A가 B에게 전달을 요청 - C에게 연락해달라고. // 그래서 C가 A에게 연락을 했을 때가 콜백을 한다고 함. B가 중간자 역할을 함. // cal을 호출하면 plus가 아닌 add 호출하여 plus값(콜백된 것)을 가져옴! }
static void Main(string[] args) { //CalDelegate cd = Add; //cd += Sub; //cd += Multiply; //cd += Divide; //// 연결해줌! //cd -= Multiply; //// 빼줌 //CalDelegate cd = new CalDelegate (Add) // + Sub // + Multiply // + Divide; CalDelegate cd = (CalDelegate)Delegate.Combine( new CalDelegate(Add), new CalDelegate(Sub), new CalDelegate(Multiply), new CalDelegate(Divide) ); cd(10, 5); }
private static void Main(string[] args) { #region Simple or Multicast Delegate // Multiple instances CalDelegate aDel, mDel, amDel, amMinusmDel; aDel = DelegateExample.Addition; mDel = DelegateExample.Multiplication; Console.WriteLine("Simple Delegate : Addition"); aDel(4, 4); Console.WriteLine("Simple Delegate : Mutliplication"); mDel(4, 4); Console.WriteLine("MultiCast Delegate : Addition + Multiplication"); amDel = aDel + mDel; amDel(4, 4); Console.WriteLine("Unlinking MultiCast Delegate : MultiCast - Multiplication"); amMinusmDel = amDel - mDel; amMinusmDel(4, 4); //Single Instance Console.WriteLine("Single Instance - Delegate"); CalDelegate cDel = new CalDelegate(DelegateExample.Addition); cDel += DelegateExample.Multiplication; cDel(9, 9); #endregion Simple or Multicast Delegate #region Normal MyDelegate myThree = new MyDelegate(SomeMethod); myThree.Invoke(); MyDelegate myTwo = SomeMethod; myTwo(); #endregion Normal }
static void Main(string[] args) { Console.WriteLine("Helo World..."); //Console.ReadLine(); //Environment.Exit(0); #region ClassMember UtilityHelper objHelper = new UtilityHelper(); List <int> numbers = new List <int>(); numbers.Add(1); numbers.Add(2); numbers.Add(-1); objHelper.numbers = numbers; objHelper.PrintNumbers(); //Console.WriteLine(objHelper.numbers); //objHelper.status = "Setter"; Console.WriteLine("Status :-" + objHelper.status); UtilityHelper objHelper1 = new UtilityHelper("Initilaizer"); //Console.ReadLine(); #endregion ClassMember #region OOPS Console.WriteLine("-----OOPS-----"); Console.WriteLine("--Word Press--"); BlogPage objBlogPage = new GoogleBlog("Google"); objBlogPage.isActive = "YES"; objBlogPage.blogPageAuthor = "DJ"; objBlogPage.blogPageName = "C# .Net Articles"; objBlogPage.AddArticles("Basics of C#"); objBlogPage.AddArticles("Basics of C# OOPS"); objBlogPage.DisplayArticle(); Console.WriteLine("------------"); objBlogPage.BlogInfo(); Console.ReadLine(); #endregion #region DesignPattern Console.WriteLine("-----OOPS-----"); Console.WriteLine("--Word Press--"); int blogType = 2; BlogPage dynamicobjBlogPage; if (blogType == 1) { dynamicobjBlogPage = new WordPressBlog("WordPress"); } else { dynamicobjBlogPage = new GoogleBlog("WordPress"); } dynamicobjBlogPage.isActive = "YES"; dynamicobjBlogPage.blogPageAuthor = "DJ"; dynamicobjBlogPage.blogPageName = "C# .Net Articles"; dynamicobjBlogPage.AddArticles("Basics of C# DesignPattern"); dynamicobjBlogPage.DisplayArticle(); Console.WriteLine("------------"); dynamicobjBlogPage.BlogInfo(); Console.ReadLine(); #endregion #region DelegateDemo CalOperations objCal = new CalOperations(); CalDelegate objDelegate = new CalDelegate(objCal.Add); objDelegate += new CalDelegate(objCal.Sub); int result = objDelegate(1, 2); Console.WriteLine("Result Set :- " + result.ToString()); #endregion #region DAL DALHelper objDAL = new DALHelper(); ClientProductModel product = new ClientProductModel(); product.Name = "IPhone"; product.Qty = "25"; product.Rate = "25.00"; // objDAL.Insert(product); product.Name = "Nokia"; product.Qty = "100"; product.Rate = "12.00"; // objDAL.Insert(product); product = null; product = objDAL.SelectQuery(1); product = objDAL.SPExecute(1); #endregion #region LINQ LinqTuto.LinqHelloWorld(); LinqTuto.LinqHelloWorldOnStudent(); LinqTuto.LinqHelloWorldOnStudentTeacher(); #endregion }
private double Cal(CalDelegate calDelegate, double a, double b) { return(calDelegate(a, b)); }
public static void Calc <T>(T x, T y, CalDelegate <T> cd) { Console.WriteLine(cd(x, y)); }
public static void Calc(int x, int y, CalDelegate cd) { Console.WriteLine(cd(x, y)); }