Yahoo Web Search

Search results

  1. Explore how to create different C# applications by using Visual Studio, including console, web, Windows Forms, and Windows Desktop apps, and find coding resources.

    • Tutorial

      In this tutorial for C# development with ASP.NET Core, you...

    • Windows

      Open Visual Studio. On the start window, choose Create a new...

    • Visual Studio

      In this article. An integrated development environment (IDE)...

    • Create a Matching Game

      Visual Studio creates a solution for your app. A solution is...

    • NET

      Build web and native applications for multiple operating...

  2. Our focus with VS Code is to be a great editor for cross-platform C# development by providing a rich C# editing experience, AI-powered development, solution management, and integrated testing experiences

    • 1.88
    • Overview
    • Prerequisites
    • Create a project
    • Create the app
    • Debug the app
    • Close the app
    • Add Git source control
    • Review: Code complete
    • Next steps

    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). This tutorial is part 1 of a two-part tutorial series.

    In this tutorial, you complete the following tasks:

    •Create a Visual Studio project.

    •Create a C# console app.

    •Debug your app.

    •Close your app.

    You must have Visual Studio installed.

    If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.

    To start, create a C# application project. The project type comes with all the template files you need.

    1.Open Visual Studio, and select Create a new project in the Start window.

    2.In the Create a new project window, choose C# from the Language list. Next, choose Windows from the Platform list and Console from the project types list.

    After you apply the language, platform, and project type filters, choose the Console Application template, and then select Next.

    3.In the Configure your new project window, type or enter Calculator in the Project name box. Then, select Next.

    4.In the Additional information window, verify that .NET Core 3.1 appears in the Target Framework field. Then, select Create.

    Explore integer math

    Start with some basic integer math in C#. 1.In the code editor, delete the default "Hello World" code. Specifically, delete the line that says, Console.WriteLine("Hello World!");. 2.In its place, enter the following code: Notice that when you enter the code, the IntelliSense feature in Visual Studio offers you the option to autocomplete the entry. 3.Select the green Start button next to Calculator to build and run your program, or press F5. A console window opens that reveals the sum of 42 + 119, which is 161. 4.(Optional) You can change the operator to change the result. For example, you can change the + operator in the int c = a + b; line of code to - for subtraction, * for multiplication, or / for division. Then, when you run the program, the result changes, too. 5.Close the console window. 1.In Solution Explorer, in the right pane, select Program.cs to display the file in the code editor 2.In the code editor, replace the default "Hello World" code that says Console.WriteLine("Hello World!");. Replace the line with the following code: If you enter the code, the Visual Studio IntelliSense feature offers you the option to autocomplete the entry. 3.To build and run your app, press F5, or select the green arrow next to the name Calculator in the top toolbar. A console window opens that shows the sum of 42 + 119, which is 161. 4.Close the console window. 5.Optionally, you can change the operator to change the result. For example, you can change the + operator in the int c = a + b; line of code to - for subtraction, * for multiplication, or / for division. When you run the app, the result changes accordingly.

    Add code to create a calculator

    Continue by adding a more complex set of calculator code to your project. 1.In the code editor, replace all the code in Program.cs with the following new code: 2.Select the Calculator button or press F5 to run your app. A console window opens. 3.In the console window, follow the prompts to add the numbers 42 and 119 together. Your app should look similar to the following screenshot: 1.In the code editor, replace all the code in Program.cs with the following new code: 2.Select the Calculator button or press F5 to run your app. A console window opens. 3.In the console window, follow the prompts to add the numbers 42 and 119 together. Your app should look similar to the following screenshot:

    Add decimal functionality

    Now, tweak the code to add more functionality. The current calculator app only accepts and returns whole numbers. For example, if you run the app and divide the number 42 by the number 119, your result is zero, which isn't exact. To fix the code to improve precision by handling decimals: 1.From Program.cs in the Visual Studio editor, press Ctrl+H to open the Find and Replace control. 2.Type int in the control, and type float in the Replace field. 3.Select the icons for Match case and Match whole word in the control, or press Alt+C and Alt+W. 4.Select the Replace all icon or press Alt+A to run the search and replace. 5.Run your calculator app again, and divide the number 42 by the number 119. The app now returns a decimal number instead of zero. Now the app can produce decimal results. Make a few more tweaks to the code so the app can calculate decimals too. 6.Use the Find and Replace control to change each instance of the float variable to double, and to change each instance of the Convert.ToInt32 method to Convert.ToDouble. 7.Run your calculator app, and divide the number 42.5 by the number 119.75. The app now accepts decimal values, and returns a longer decimal numeral as its result. In the Revise the code section, you reduce the number of decimal places in the results.

    You improved your basic calculator app, but your app doesn't yet handle exceptions, such as user input errors. For example, if users try to divide by zero, or enter an unexpected character, the app might stop working, return an error, or return an unexpected non-numeric result.

    Let's walk through a few common user input errors, locate them in the debugger if they appear there, and fix them in the code.

    1.If you haven't already done so, close the Calculator app.

    2.Close the Output pane in Visual Studio.

    Now that you've created an app, you might want to add it to a Git repository. Visual Studio makes that process easy with Git tools you can use directly from the IDE.

    To associate your code with Git, start by creating a new Git repository where your code is located:

    1.In the status bar at the bottom-right corner of Visual Studio, select Add to Source Control, and then select Git.

    2.In the Create a Git repository dialog box, sign in to GitHub.

    The repository name auto-populates based on your folder location. Your new repository is private by default, which means you're the only one who can access it.

    3.Select Create and Push.

    In this tutorial, you made many changes to the Calculator app. The app now handles computing resources more efficiently, and handles most user input errors.

    Here's the complete code, all in one place:

    Continue with the second part of this tutorial:

    Tutorial Part 2: Extend and debug your C# console app

  3. The C# extension is called C# Dev Kit and it's published by Microsoft. Note: C# Dev Kit supports cloud native development. To do cross-platform mobile and desktop development, you can use C# Dev Kit with the .NET MAUI extension. Learn how to get set up with .NET MAUI in VS Code. Upon installation, C# Dev Kit launches an extension walkthrough.

    • 1.88
  4. C# is an object-oriented programming language that enables developers to build a variety of secure and robust application that run on the .NET. Let's make our first C# Hello World console application and run it in Visual Studio Code! Interested in learning C# but aren't sure where to start? Start here! All learning materials.

  5. People also ask

  1. People also search for