::: moniker-end Add decimal functionality Your app should look similar to the following screenshot: In the console window, follow the prompts to add the numbers 42 and 119 together. Select the Calculator button or press F5 to run your app. Write( "Press any key to close the Calculator console app. Wait for the user to respond before closing. WriteLine( $"Your result: = " ( num1 / num2)) Use a switch statement to do the math. WriteLine( "Choose an option from the following list: ") WriteLine( "Type another number, and then press Enter ") Ask the user to type the second number. WriteLine( "Type a number, and then press Enter ") Ask the user to type the first number. WriteLine( "Console Calculator in C# \r ") Ĭonsole. Display title as the C# console calculator app. Declare variables and then initialize to zero. Specifically, delete the line that says, Console.WriteLine("Hello World!"). In the code editor, delete the default "Hello World" code. Start with some basic integer math in C#. Refine the code to make it more efficient.Add code to create a basic calculator app.To learn more, see the New C# templates generate top-level statements page. NET 6, new projects using the console template generate different code than previous versions. Press any key to close the console window. After the application runs in the debugger, the console window stays open. If you press F5, you can run the default program in Debug mode. The single code statement calls the xref:* method to display the literal string "Hello, World!" in the console window. NET 6.0 should already be selected for your target framework. In the Configure your new project window, type or enter Calculator in the Project name box, and then select Next. NET desktop development workload, and then select Modify. In the Visual Studio Installer, choose the. If you don't see the Console App template, select Install more tools and features. Choose Windows from the All platforms list, and choose Console from the All project types list.Īfter you apply the language, platform, and project type filters, choose the Console App template, and then select Next. In the Create a new project window, select All languages, and then choose C# from the dropdown list. The default "Hello World" code calls the xref:* method to display the literal string "Hello, World!" in the console window. To view it in the editor, select the code file Program.cs in the Solution Explorer window, which is typically on the right-hand side of Visual Studio. Visual Studio opens your new project, which includes default "Hello World" code. NET Core 3.1 is selected in the 'In the 'Additional information' window."::: :::image type="content" source="./media/vs-2019/csharp-target-framework.png" alt-text="Screenshot that shows making sure. NET Core 3.1 should already be selected for your target framework. :::image type="content" source="./media/vs-2019/csharp-name-your-calculator-project.png" alt-text="Screenshot that shows naming your project 'Calculator' in the 'Configure your new project' window."::: In the Configure your new project window, type or enter Calculator in the Project name box. Then, return to step 2 in this " Create a project" procedure. Next, choose Continue to install the workload. You might be prompted to save your work if so, do so. NET Core cross-platform development workload.Īfter that, choose the Modify button in the Visual Studio Installer. Then, in the Visual Studio Installer, choose the. If you don't see the Console Application template, select Install more tools and features. Next, choose Windows from the Platform list and Console from the project types list.Īfter you apply the language, platform, and project type filters, choose the Console Application template, and then select Next. In the Create a new project window, choose C# from the Language list. Open Visual Studio, and choose Create a new project in the Start window. The project type comes with all the template files you need. To start, create a C# application project. If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free. In part 2, you extend this app to add more projects, learn debugging tricks, and reference third-party packages. This tutorial is part 1 of a two-part tutorial series. In this tutorial, you use Visual Studio to create and run a C# console app, and explore some features of the Visual Studio integrated development environment (IDE). Tutorial: Create a simple C# console app in Visual Studio (part 1 of 2)
0 Comments
Leave a Reply. |