public HeroMenu(ISuperHeroRepo repo, IMessagingService service) { this.repo = repo; this.service = service; tasks = new HerosLib.HeroTasks(); this.heroService = new HeroService(repo); }
static void Main(string[] args) { Hero obj = new Hero(); #region default constructor /*Hero obj = new Hero(); * Console.WriteLine($"{obj.id} {obj.name}");*/ #endregion #region paramaterized constructor // Hero obj1 = new Hero(2, "Deadpool"); // Console.WriteLine($"{obj1.id} {obj1.name}"); //Cannot access the variables if they're not public #endregion #region Access via Properties // Console.WriteLine(obj1.Id); //read property value // obj1.Id = 3; // Console.WriteLine($"New ID = {obj1.Id}"); //Write into a property #endregion #region accessing 1-D arrays /*Console.Write("Please enter your hero ID: "); * obj.Id = Int32.Parse(Console.ReadLine()); * * Console.Write("Please enter your superhero name: "); * obj.name = Console.ReadLine(); * * Console.Write("Enter the first power: "); * obj.superPowers[0] = Console.ReadLine(); * * Console.Write($"{obj.Id} {obj.name} {obj.superPowers[0]}");*/ #endregion #region Accessing Jagged arrays /*obj.ja[0] = new int[2]; //first column * obj.ja[1] = new int[3]; //second column * obj.ja[2] = new int[1]; //third column * * obj.ja[0][0] = 10; //initialize value of first row and first column to 10 * obj.ja[1][2] = 15; * * int[,,] td = new int[2,3,4]; * Console.WriteLine($"Dimension of the array - {td.Rank}D"); * Console.WriteLine($"Number of elements in the Array - {td.Length}"); * * Console.Write(obj.ja.Rank); //rank is the dimension of the array * Console.Write(obj.ja.Length); //length is elements of the arrays * * //Loop through the jagged array * foreach (var rows in obj.ja) { //looping through all rows * * //looping through all columns of every row * for(int i = 0; i < rows.Length; i++){ * Console.Write($" {rows[i]} "); * } * Console.WriteLine(); * }*/ #endregion #region List<T> Example & Stack<T> & Dictionary<Tkey, Value> Example // Console.WriteLine("Please enter the super power to be removed: "); // string sp = Console.ReadLine(); // Hero.superPowers.Remove(sp); // foreach(var superPowers in Hero.GetSuperPowers()) { // Console.WriteLine(superPowers); // } /*Console.WriteLine("Super Hero Hideout"); * foreach(var superHeroes in Hero.hideOuts) { * // Console.WriteLine($"{superHeroes.Key} {superHeroes.Value}"); * Console.WriteLine($"{superHeroes.Key} {Hero.hideOuts[superHeroes.Key]}"); //can also do this way * }*/ #endregion #region Calling Hero menu IMenu startMenu = new MainMenu(); startMenu.Start(); #endregion HeroTasks heroTasks = new HeroTasks(); #region Delegate, Anonymous methods, Lambda // HeroDel del = new HeroDel(heroTasks.GetPowers); // Action del = new Action(heroTasks.GetPowers); // Func<string, string> fd = new Func<string,string>(some method); // Predicate<string> predicate = new Predicate<string>(some method); // del += heroTasks.DoWork; // += subscribe to a method // del += heroTasks.ManageLife; // del(); // del -= heroTasks.ManageLife; // -= unsubscribe // del(); //Anonymous methods // Action<string> am = delegate(string name) { // System.Console.WriteLine("Hello anonymous"); // }; // am("Lindsey"); //Lambda Expression - shorthand notation to anonymous methods // Action result = () => System.Console.WriteLine("Hello Lambda"); // result(); #endregion #region Async VS synchronous programming //Subscribing to publisher /*heroTasks.workDone += EmailService.SendEmail; * heroTasks.workDone += TextMessageService.SendText; * heroTasks.workDone += PushNotification.SendPushNotification; * * heroTasks.DoWork(); * heroTasks.ManageLife(); * Console.Read(); //Holds the stream until a key is pressed (& waits for the other thread instead of ending execution)*/ #endregion }
static void Main(string[] args) { //Hero obj=new Hero(); #region default constructor /*Hero obj=new Hero(); * Console.WriteLine($"{obj.id} {obj.name}" );*/ #endregion #region Parameterized constructor //Hero obj1=new Hero(2, "Narco"); //Program obj1=new Program(); //Console.WriteLine($"{obj1.id} {obj1.name}" );// cannot access the variable if they arenot public #endregion #region Access via Properties // Console.WriteLine(obj1.Id);// read property value // obj1.Id=3; // Console.Write($"New Id = {obj1.Id}");// write into a property #endregion #region Accessing Arrays /*Console.Write("Please enter your heros id: "); * obj.Id=Int32.Parse(Console.ReadLine()); * Console.Write("Please enter your Superhero name:"); * obj.Name=Console.ReadLine(); * Console.Write("Enter the first Power: "); * obj.superPowers[0] * Console.ReadLine(); * Console.Write($"{obj.Id} {obj.Name} {obj.superPowers[0]}");*/ // Jagged Arrays rows initializations /*obj.ja[0]=new int[2];// first column * obj.ja[1]=new int[3];// second column * obj.ja[2]=new int[1];// third column * obj.ja[0][0]=10; * obj.ja[1][2]=15; * int[,,] td=new int[2,4,3];// 3-D arrays * Console.WriteLine($"Dimension of the Array - {td.Rank}D"); * Console.WriteLine($"Number of elements in the Array - {td.Length}"); * Console.WriteLine(obj.ja.Rank);// rank is dimenssion of the array * Console.WriteLine(obj.ja.Length);// elements of the arrays * // loop through the jagged array * foreach (var rows in obj.ja) //looping through all rows * { * //looping through all columns of every row * for(int i=0; i<rows.Length;i++){ * Console.Write($"{rows[i]} "); * } * Console.WriteLine(); * }*/ #endregion #region List<T>, Stack<T> //Console.WriteLine("Please enter the super power to be removed "); //string sp=Console.ReadLine(); //Hero.superPowers.Remove(sp); // foreach(var superPower in Hero.GetSuperPowers()){ // Console.WriteLine(superPower); // } #endregion #region Dictionary<key, value> // Console.WriteLine("Super Hero Hideout"); // foreach(var superhero in Hero.hideOuts){ // // Console.WriteLine($"{superhero.Key} {Hero.hideOuts[superhero.Key]}"); // old way // //Console.WriteLine($"{superhero.Key} {superhero.Value}"); // new way of accessing key values // } #endregion #region Calling hero menu // IMenu startMenu = new MainMenu(); // startMenu.Start(); #endregion #region Delegate, Anonymous methods, Lambda HeroTasks heroTasks = new HeroTasks(); //HeroDel del=new HeroDel(heroTasks.GetPowers); Action del = new Action(heroTasks.GetPowers); //Func<string, string> fd=new Func<string, string>(some method); //Predicate<string> predicate=new Predicate<string>(some method); del += heroTasks.DoWork; // += subscribe to a method del += heroTasks.ManageLife; del(); del -= heroTasks.ManageLife; // unsubscribe del(); // Anonymous methods Action <string> am = delegate(string name){ Console.WriteLine("Hello anonymous"); }; am("Pushpinder"); // Lambda expression - shorthand notations to anonymous methods Action result = () => Console.WriteLine("Hello Lambda"); result(); #endregion }
static void Main(string[] args) { //Hero obj = new Hero(); #region default constructor /*Hero obj = new Hero(); * Console.WriteLine($"Hero ID: {obj.id} \nHero Name: {obj.name}");*/ #endregion #region explicit constructor /*obj.Id = 5; * Console.WriteLine($"Hero ID: {obj.Id} \nHero Name: {obj.name}");*/ #endregion #region arrays /* * Console.Write("Please enter your hero's id: "); * obj.Id=Int32.Parse(Console.ReadLine()); //typecast string to int * Console.Write("Please enter your Superhero name: "); * obj.Name=Console.ReadLine(); * Console.Write("Please enter the first superpower: "); * obj.superPowers[0] = Console.ReadLine(); * Console.Write($"ID: {obj.Id}\nName: {obj.Name}\nSuperpowers: {obj.superPowers[0]}"); */ #endregion #region accessing arrays /* * obj.ja[0] = new int[2]; * obj.ja[1] = new int[3]; * obj.ja[2] = new int[1]; * obj.ja[0][0] =10; * obj.ja[1][2] =15; * int[,,] td = new int[2, 4, 3]; //3-D array * //Console.WriteLine(obj.ja.Rank); //dimension of the array (1D, 2D, etc.) (jagged arrays are techincally 1D) * //Console.WriteLine(obj.ja.Length);//maximum size of the array (num of elements) * * Console.WriteLine("Values in Jagged Array:"); * //loop through all rows * foreach (var row in obj.ja) * { * //loop through all columns * foreach (var val in row) * { * Console.Write($"{val} "); * } * Console.Write("\n"); * } */ #endregion #region List<T> /* * Console.Write("Remove super power: "); * string sp=Console.ReadLine(); * //Hero.superPowers.Remove(sp); * * Console.Write("\n"); * foreach(var superPower in Hero.GetSuperPowers()) * { * Console.WriteLine(superPower); * }*/ #endregion #region Dictionary<key, value> /* * Console.WriteLine("Superhero Hideout"); * foreach(var superhero in Hero.hideOuts) { * Console.WriteLine($"{superhero.Key} {Hero.hideOuts[superhero.Key]}"); * }*/ #endregion #region calling Hero menu /* * MainMenu startMenu = new MainMenu(); * startMenu.Start();*/ #endregion HeroTasks heroTasks = new HeroTasks(); #region delegates, anonymous members, lambda /* * HeroDel del = new HeroDel(heroTasks.GetPowers); * del += heroTasks.DoWork; //+= subscribe to a method * //del -= heroTasks.DoWork; //-= unsubscribes to a method * del += heroTasks.ManageLife; * del(); * //Func<string, string> fd; * //Predicate<string> predicate; * * //Anonymous methods * Action<string> am = delegate(string name) { * System.Console.WriteLine("Hello anonymous"); * }; * am("foo"); * //Lambda expression --> shorthand for anonymous method * Action<string> lm = (string name) => Console.WriteLine("Hello lambda"); * lm("foo");*/ #endregion #region asynchronous vs. synchronous programming //Subscribing to publisher heroTasks.workDone += EmailService.SendEmail; heroTasks.workDone += TextMessageService.SendText; heroTasks.workDone += PushNotification.SendPushNotification; heroTasks.DoWork(); //this will create a second thread and process it in the background heroTasks.ManageLife(); //this will be processed by the main thread Console.Read(); //this is to make the console wait while the second thread processes #endregion }
static void Main(string[] args) { #region default constructor // Hero obj = new Hero(); // Console.WriteLine($"{obj.id} {obj.name}"); #endregion #region parameterized constructor // Hero obj1 = new Hero(2, "Narco"); // Console.WriteLine($"{obj1.id} {obj1.name}"); #endregion #region access via properties // Console.WriteLine($"ID = {obj1.Id}"); // read property value // obj1.Id = 3; // write into property // Console.WriteLine($"Updated ID = {obj1.Id}"); #endregion // Hero obj = new Hero(); // Console.Write("Please enter your hero's ID: "); // obj.Id = Int32.Parse(Console.ReadLine()); // Console.Write("Please enter your hero's name: "); // obj.Name = Console.ReadLine(); // Console.Write("Please enter the first superpower: "); // obj.superPowers[0] = Console.ReadLine(); // Console.Write($"{obj.Id} {obj.Name} {obj.superPowers[0]}"); #region List<T>, Stack<T> // Console.WriteLine("Please enter the superpower to be removed: "); // string sp = Console.ReadLine(); // Hero.RemoveSuperPower(sp); // Hero.RemoveSuperPower(); // foreach(var superPower in Hero.GetSuperPowers()) { // Console.WriteLine(superPower); // } #endregion #region Dictionary<key, value> // Console.WriteLine("Superhero/Hideout:"); // foreach(var superhero in Hero.hideOuts) { // // Console.WriteLine($"{superhero.Key} / {superhero.Value}"); // Console.WriteLine($"{superhero.Key} / {Hero.hideOuts[superhero.Key]}"); // } #endregion #region calling hero menu IMenu startMenu = new MainMenu(); startMenu.Start(); #endregion HeroTasks heroTask = new HeroTasks(); #region delegates, anonymous methods, lambda functions // HeroDel del = new HeroDel(heroTask.GetSuperPowers); Action del = new Action(heroTask.GetSuperPowers); // strongly-typed pre-defined delegate del += heroTask.DoWork; // subscribe to a method with += del += heroTask.ManageLife; del(); del -= heroTask.ManageLife; // unsubscribe with -= del(); // anonymous methods Action <string> am = delegate(string name) { Console.WriteLine("Hello anonymous"); }; am("me"); // lambda expressions => shorthand notations to anonymous methods Action result = () => Console.WriteLine("Hello lambda"); result(); #endregion #region synchronous vs asynchronous programming // subscribing to publisher heroTask.workDone += EmailService.SendEmail; heroTask.workDone += TextMessageService.SendText; heroTask.workDone += PushNotificationService.SendPushNotification; heroTask.DoWork(); heroTask.ManageLife(); // System.Threading.Thread.Sleep(2000); Console.Read(); // holds the screen until key is pressed #endregion }
static void Main(string[] args) { #region default constructor #endregion #region Parameterized constructor // Hero obj = new Hero(1, "brian"); // Console.WriteLine($"{obj.Id} {obj.name}"); #endregion #region access via properties // obj.Id = 2; // Console.WriteLine($"New Id = {obj.Id}"); #endregion #region Accessing 1-D Arrays Hero obj = new Hero(); // Console.Write("Please Enter your heros id: "); // obj.Id = Int32.Parse(Console.ReadLine()); // Console.Write("Please Enter your heros name: "); // obj.Name = Console.ReadLine(); // Console.Write("Enter the first super power: "); // obj.superPowers[0] = Console.ReadLine(); // Console.Write($"{obj.Id} {obj.Name} {obj.superPowers[0]}"); // obj.ja[0] = new int[2]; // first column // obj.ja[1] = new int[3]; // second column // obj.ja[2] = new int[2]; // third column // obj.ja[0][0] = 10; // obj.ja[1][2] = 15; // Console.WriteLine(obj.ja.Length); // Console.WriteLine(); // for(int i = 0; i < obj.ja.Length; i++) { // for(int j = 0; j < obj.ja[i].Length; j++) { // Console.WriteLine(obj.ja[i][j]); // } // } // foreach (var rows in obj.ja) { // foreach (var item in rows) { // Console.Write($"{item} "); // } // Console.WriteLine(); // } #endregion #region collections // foreach(var superPower in obj.GetSuperPowers()) { // Console.WriteLine(superPower); // } // Console.WriteLine("Please enter the super power to be removed "); // string sp = Console.ReadLine(); // obj.RemoveSuperPower(sp); // foreach(var superPower in obj.GetSuperPowers()) { // Console.WriteLine(superPower); // } #endregion #region traverse dictionary // Console.WriteLine("Super Hero Hideout"); // foreach(var superHero in Hero.hideouts) { // Console.WriteLine($"{superHero.Key} {superHero.Value}"); // } #endregion #region Calling hero menu // IMenu startMenu = new MainMenu(); // startMenu.Start(); #endregion #region Delegate, Anonymous methods, Lambda HeroTasks heroTasks = new HeroTasks(); //HeroDel del=new HeroDel(heroTasks.GetPowers); //Action del =new Action(heroTasks.GetPowers); //Func<string, string> fd=new Func<string, string>(some method); //Predicate<string> predicate=new Predicate<string>(some method); // del += heroTasks.DoWork; // += subscribe to a method // del += heroTasks.ManageLife; // del(); // del -= heroTasks.ManageLife; // unsubscribe // del(); //Anonymous methods // Action<string> am=delegate(string name){ // Console.WriteLine($"Hello {name}"); // }; // am("Brian"); //Lambda expression - shorthand notations to anonymous methods // Action result= ()=>Console.WriteLine("Hello Lambda"); // result(); #endregion #region Async and Sync programming /// Subscribing to publisher heroTasks.workDone += EmailService.SendEmail; heroTasks.workDone += TextMessageService.SendText; heroTasks.DoWork(); heroTasks.ManageLife(); Console.Read(); //hold the screen until a key is pressed #endregion }