static void Main(string[] args) { PlayerInformationWithScore playerOne = new PlayerInformationWithScore(DisplayInformation); PlayerInformationBasedOnNumberAndClub playerTwo = new PlayerInformationBasedOnNumberAndClub(DisplayInformation); //playerOne("chris", 20); //playerTwo(7, "cool"); Console.WriteLine(playerTwo.Method); foreach (var item in playerTwo.Method.GetParameters()) { Console.WriteLine($"{item.ParameterType}, {item.Name}, {item.Position}, {item.DefaultValue}, {item.IsOptional} "); } }
static void Main(string[] args) { PlayerInformationWithGoals playerOne = new PlayerInformationWithGoals(DisplayInformation); PlayerInformationBasedOnNumberAndClub playerTwo = new PlayerInformationBasedOnNumberAndClub(DisplayInformation); //playerOne("Ronaldo", 50); //playerTwo(7, "Real Madrid","Portugal"); Console.WriteLine(playerTwo.Method); //method keyword get parameters from below and displays them. Console.WriteLine("------------"); foreach (var item in playerTwo.Method.GetParameters()) { Console.WriteLine($"{item.ParameterType.Name}, {item.Name}, {item.Position}, {item.IsOptional}, {item.DefaultValue} "); //access and displays each of the parameters in the display method. Console.WriteLine("------------"); } }
static void Main(string[] args) { PlayerInfoDelegate messi = new PlayerInfoDelegate(DisplayInformation); messi(); PlayerInfoWithNameDelegate playerName = new PlayerInfoWithNameDelegate(DisplayInformation); playerName("ronaldo"); PlayerInfoWithNameAndGoalsDelegate anotherPlayer = new PlayerInfoWithNameAndGoalsDelegate(DisplayInformation); anotherPlayer("Messi", 60); PlayerBasedOnNumber newPlayer = new PlayerBasedOnNumber(DisplayInformation); Console.WriteLine(newPlayer(10)); PlayerInformationBasedOnNumberAndClub playerOne = new PlayerInformationBasedOnNumberAndClub(DisplayInformation); playerOne(7, "Real Madrid"); // Create a dictionary that will be used in a delegate Dictionary <int, string> listOfItems = new Dictionary <int, string>(); listOfItems.Add(1, "Item One"); listOfItems.Add(2, "Item Two"); listOfItems.Add(3, "Item Three"); listOfItems.Add(4, "Item Four"); listOfItems.Add(5, "Item Five"); DisplayDictionaryContent content = new DisplayDictionaryContent(DisplayDataDictionary); content(listOfItems); }
static void Main(string[] args) { PlayerInfoDel ronaldinho = new PlayerInfoDel(DisplayInformation); ronaldinho(); PlayerInfoWithNameDel playerName = new PlayerInfoWithNameDel(DisplayInformation); playerName("Messi"); PlayerInfoNameWithGoalsDel newPlayer = new PlayerInfoNameWithGoalsDel(DisplayInformation); newPlayer("Ronaldo", 60); newPlayer("Rooney", 25); PlayerBasedOnNumber number = new PlayerBasedOnNumber(DisplayInformation); Console.WriteLine(number(8)); Console.WriteLine(number(10)); PlayerInformationWithGoals playerOne = new PlayerInformationWithGoals(DisplayInformation2); PlayerInformationBasedOnNumberAndClub playerTwo = new PlayerInformationBasedOnNumberAndClub(DisplayInformation2); //playerOne("Ronaldo", 50); //playerTwo(7, "Real Madrid","Portugal"); Console.WriteLine(playerTwo.Method); foreach (var item in playerTwo.Method.GetParameters()) { Console.WriteLine($"{item.ParameterType.Name}, {item.Name}, {item.Position}, {item.IsOptional}, {item.DefaultValue} "); } SayHiDelegate sayHi = null; sayHi = new SayHiDelegate(SayHiEnglish); sayHi += new SayHiDelegate(SayHiSpanish); sayHi += new SayHiDelegate(SayHiJapanese); sayHi += new SayHiDelegate(SayHiItalian); sayHi += new SayHiDelegate(SayHiGerman); sayHi += new SayHiDelegate(SayHiArabic); sayHi(); //genreic delegate Console.WriteLine("------Generic Delegate------"); DisplayInfo <int> myNumber = new DisplayInfo <int>(DisplayValue); Console.WriteLine(myNumber(42)); DisplayInfo <double> myDoubleNumber = new DisplayInfo <double>(DisplayValue); Console.WriteLine(myDoubleNumber(34.32)); DisplayInfo <DateTime> myDate = new DisplayInfo <DateTime>(DisplayValue); Console.WriteLine(myDate(new DateTime(2010, 2, 23))); //Anonymous Method Multiply MultiplyNumber = delegate(int n) { { return(n * 3); } }; Console.WriteLine(MultiplyNumber(10)); DisplayMessage Message = delegate { Console.WriteLine("Hi from the anonymous method "); }; Message(); //Lambda\ Console.WriteLine("-------Lambda-------"); MultiplyLambda MultiplyNumberLambda = n => n * 3; Console.WriteLine(MultiplyNumber(10)); DisplayMessageLambda MessageLambda = () => Console.WriteLine("Hi from anonymous lambda"); Message(); //Func Delegate Console.WriteLine("------Func Delegate-----"); Func <int, int, int> funcOne = AddTwoNumbers; Console.WriteLine(AddTwoNumbers(3, 5)); Func <int> funcTwo = AddTwoNumbers; Console.WriteLine(funcTwo()); //Action Delegate Console.WriteLine("------Action Delegate--------"); Action <int> actionOne = DisplayInformationActionDelegate; actionOne(16); Action actionTwo = DisplayInformationActionDelegate; actionTwo(); //Predict Delegate Console.WriteLine("-------Predict Delegate------"); Predicate <int> condition = IsAdmin; Console.WriteLine(condition(11)); Console.WriteLine(condition(10)); }