locked
How to fix the error? RRS feed

  • Question

  • Hi Castorix and all Others,

    Thanks for replying me for my questions on https://social.msdn.microsoft.com/Forums/it-IT/2df91ac0-ea70-4ef3-a892-e53ecb990ac8/how-to-remove-red-lines?forum=csharpgeneral. I left a message for you on that page. However I guess you had not go back to that page to read it. Thus I start a new thread here. The following code is copied from the webpage that you gave me. Anything wrong with my copy?

    using System;

    using System.Threading.Tasks; class program { static void Main() { { Coffee cup = PourCoffee(); Console.WriteLine("coffee is ready"); Egg eggs = await FryEggsAsync(2); Console.WriteLine("eggs are ready"); Bacon bacon = await FryBaconAsync(3); Console.WriteLine("bacon is ready"); Toast toast = await ToastBreadAsync(2); ApplyButter(toast); ApplyJam(toast); Console.WriteLine("toast is ready"); Juice oj = PourOJ(); Console.WriteLine("oj is ready"); Console.WriteLine("Breakfast is ready!"); } // </SnippetMain> private static Juice PourOJ() { Console.WriteLine("Pouring orange juice"); return new Juice(); } private static void ApplyJam(Toast toast) => Console.WriteLine("Putting jam on the toast"); private static void ApplyButter(Toast toast) => Console.WriteLine("Putting butter on the toast"); private static async Task<Toast> ToastBreadAsync(int slices) { for (int slice = 0; slice < slices; slice++) { Console.WriteLine("Putting a slice of bread in the toaster"); } Console.WriteLine("Start toasting..."); await Task.Delay(3000); Console.WriteLine("Remove toast from toaster"); return new Toast(); } private static async Task<Bacon> FryBaconAsync(int slices) { Console.WriteLine($"putting {slices} slices of bacon in the pan"); Console.WriteLine("cooking first side of bacon..."); await Task.Delay(3000); for (int slice = 0; slice < slices; slice++) { Console.WriteLine("flipping a slice of bacon"); } Console.WriteLine("cooking the second side of bacon..."); await Task.Delay(3000); Console.WriteLine("Put bacon on plate"); return new Bacon(); Console.WriteLine("cooking the eggs ..."); await Task.Delay(3000); Console.WriteLine("Put eggs on plate"); return new Egg(); } Console.WriteLine("Pouring coffee"); return new Coffee(); } }





    • Edited by BenTam Thursday, August 6, 2020 2:35 PM
    Thursday, August 6, 2020 2:18 PM

Answers

  • Hi BenTam,

    I have changed some places in your code, and it could build and debug on my side. Please check it:

    using System;
    using System.Threading.Tasks;
    
    class program
    {
        static async Task Main()
        {
            {
                Coffee cup = PourCoffee();
                Console.WriteLine("coffee is ready");
    
                Egg eggs = await FryEggsAsync(2);
                Console.WriteLine("eggs are ready");
    
                Bacon bacon = await FryBaconAsync(3);
                Console.WriteLine("bacon is ready");
    
                Toast toast = await ToastBreadAsync(2);
                ApplyButter(toast);
                ApplyJam(toast);
                Console.WriteLine("toast is ready");
    
                Juice oj = PourOJ();
                Console.WriteLine("oj is ready");
    
                Console.WriteLine("Breakfast is ready!");
            }
        }
        // </SnippetMain>
    
        private static Juice PourOJ()
        {
    
            Console.WriteLine("Pouring orange juice");
            return new Juice();
        }
    
        private static void ApplyJam(Toast toast) =>
        Console.WriteLine("Putting jam on the toast");
    
        private static void ApplyButter(Toast toast) =>
        Console.WriteLine("Putting butter on the toast");
    
        private static async Task<Toast> ToastBreadAsync(int slices)
        {
            for (int slice = 0; slice < slices; slice++)
            {
                Console.WriteLine("Putting a slice of bread in the toaster");
            }
            Console.WriteLine("Start toasting...");
            await Task.Delay(3000);
            Console.WriteLine("Remove toast from toaster");
    
            return new Toast();
        }
    
        private static async Task<Bacon> FryBaconAsync(int slices)
        {
            Console.WriteLine($"putting {slices} slices of bacon in the pan");
            Console.WriteLine("cooking first side of bacon...");
            await Task.Delay(3000);
            for (int slice = 0; slice < slices; slice++)
            {
                Console.WriteLine("flipping a slice of bacon");
            }
            Console.WriteLine("cooking the second side of bacon...");
            await Task.Delay(3000);
            Console.WriteLine("Put bacon on plate");
    
            return new Bacon();
        }
        private static async Task<Egg> FryEggsAsync(int howMany)
        {
            Console.WriteLine("cooking the eggs ...");
            await Task.Delay(3000);
            Console.WriteLine("Put eggs on plate");
    
            return new Egg();
        }
    
        private static Coffee PourCoffee()
        {
            Console.WriteLine("Pouring coffee");
            return new Coffee();
        }
    }
    
    #region breakfast class
    internal class Coffee
    {
    }
    
    internal class Bacon
    {
    }
    
    internal class Egg
    {
    }
    
    internal class Juice
    {
    }
    
    internal class Toast
    {
    }
    #endregion

    The result:

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    • Marked as answer by BenTam Friday, August 7, 2020 3:49 AM
    Friday, August 7, 2020 3:11 AM

All replies

  • Hi BenTam,

    I have changed some places in your code, and it could build and debug on my side. Please check it:

    using System;
    using System.Threading.Tasks;
    
    class program
    {
        static async Task Main()
        {
            {
                Coffee cup = PourCoffee();
                Console.WriteLine("coffee is ready");
    
                Egg eggs = await FryEggsAsync(2);
                Console.WriteLine("eggs are ready");
    
                Bacon bacon = await FryBaconAsync(3);
                Console.WriteLine("bacon is ready");
    
                Toast toast = await ToastBreadAsync(2);
                ApplyButter(toast);
                ApplyJam(toast);
                Console.WriteLine("toast is ready");
    
                Juice oj = PourOJ();
                Console.WriteLine("oj is ready");
    
                Console.WriteLine("Breakfast is ready!");
            }
        }
        // </SnippetMain>
    
        private static Juice PourOJ()
        {
    
            Console.WriteLine("Pouring orange juice");
            return new Juice();
        }
    
        private static void ApplyJam(Toast toast) =>
        Console.WriteLine("Putting jam on the toast");
    
        private static void ApplyButter(Toast toast) =>
        Console.WriteLine("Putting butter on the toast");
    
        private static async Task<Toast> ToastBreadAsync(int slices)
        {
            for (int slice = 0; slice < slices; slice++)
            {
                Console.WriteLine("Putting a slice of bread in the toaster");
            }
            Console.WriteLine("Start toasting...");
            await Task.Delay(3000);
            Console.WriteLine("Remove toast from toaster");
    
            return new Toast();
        }
    
        private static async Task<Bacon> FryBaconAsync(int slices)
        {
            Console.WriteLine($"putting {slices} slices of bacon in the pan");
            Console.WriteLine("cooking first side of bacon...");
            await Task.Delay(3000);
            for (int slice = 0; slice < slices; slice++)
            {
                Console.WriteLine("flipping a slice of bacon");
            }
            Console.WriteLine("cooking the second side of bacon...");
            await Task.Delay(3000);
            Console.WriteLine("Put bacon on plate");
    
            return new Bacon();
        }
        private static async Task<Egg> FryEggsAsync(int howMany)
        {
            Console.WriteLine("cooking the eggs ...");
            await Task.Delay(3000);
            Console.WriteLine("Put eggs on plate");
    
            return new Egg();
        }
    
        private static Coffee PourCoffee()
        {
            Console.WriteLine("Pouring coffee");
            return new Coffee();
        }
    }
    
    #region breakfast class
    internal class Coffee
    {
    }
    
    internal class Bacon
    {
    }
    
    internal class Egg
    {
    }
    
    internal class Juice
    {
    }
    
    internal class Toast
    {
    }
    #endregion

    The result:

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    • Marked as answer by BenTam Friday, August 7, 2020 3:49 AM
    Friday, August 7, 2020 3:11 AM
  • Hi Dylan,

    Thanks for your reply and solutions.

    Friday, August 7, 2020 3:49 AM