Share via

Debug101 C#

Pardon, Sam 0 Reputation points
2024-06-05T23:49:50.5866667+00:00

Conducting this training in Visual Studio, not VS Code as demonstrated.
I am having trouble following the config of a project for debugging.
Specificly around having a sln file and building to obtain with a launch.jsoon

This question is related to the following Learning Module

Azure | Azure Training
0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2024-06-06T04:33:39.6966667+00:00

    Hi Pardon, Sam,

    Thank you for reaching out to Microsoft Q & A forum.   

    While Visual Studio Code (VS Code) is commonly used in Microsoft Learn paths due to its lightweight, cross-platform nature and extensive customization options, Visual Studio provides a robust integrated environment suited for complex, large-scale development projects. VS Code is valued for: 

    Cross-Platform Compatibility: Works on Windows, macOS, and Linux. 

    Extensibility: Supports a wide range of languages and workflows through extensions. 

    Integrated Tools: Offers built-in terminal and Git support, enhancing productivity. 

    Visual Studio Code's popularity in tutorials is due to its flexibility and cross-platform nature, while Visual Studio offers a more integrated environment for large projects.

    These are the steps to write and debug a console application in Visual Studio:

    1.Create a New Project in Visual Studio: 

    1.Open Visual Studio. 

    2.Create a new project: 

    Navigate to File > New > Project. 

    Choose Console App (.NET Core). 

    Name it Debug101 and click Create. 

    2. Add Code to Program.cs: 

    1.Open Program.cs from Solution Explorer. 

    2.Replace the existing code with the following: 

    using System;
    
    string[] names = new string[] { "Sophia", "Andrew", "AllGreetings" };
    
    string messageText = "";
    
    foreach (string name in names)
    {
        if (name == "Sophia")
            messageText = SophiaMessage();
        else if (name == "Andrew")
            messageText = AndrewMessage();
        else if (name == "AllGreetings")
            messageText = SophiaMessage();
            messageText = messageText + "\n\r" + AndrewMessage();
    
        Console.WriteLine(messageText + "\n\r");
    }
    
    bool pauseCode = true;
    while (pauseCode == true);
    
    static string SophiaMessage()
    {
        return "Hello, my name is Sophia.";
    }
    
    static string AndrewMessage()
    {
        return "Hi, my name is Andrew. Good to meet you.";
    }
    
    

    3.Save the file with Ctrl+S. 

    3. Build the Project 

    1.Build the solution: 

    Go to Build > Build Solution or press Ctrl+Shift+B. 

    4.Set Up Debugging: 

    1.Set breakpoints by clicking in the left margin next to the line numbers in Program.cs. 

    2.Start debugging: 

    Go to Debug > Start Debugging or press F5. 

    5.Inspect and Control Execution: 

    1.Use the debug toolbar to step through code, inspect variables, and view the call stack. 

    2.Examine the output in the Output window. 

    Please feel free to contact us if you have any additional questions.    

    If you have found the answer provided to be helpful, please click on the "Accept answer/Upvote" button so that it is useful for other members in the Microsoft Q&A community.       

    Thank you. 

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.