Visual studio (MAC) Console Application [duplicate] Ask Question 5. Browse other questions tagged c# macos visual-studio console-application visual-studio-mac or ask your own question. 2 years, 1 month ago. 10,019 times. 1 year, 8 months ago.
-->This topic provides a step-by-step introduction to building, debugging, and publishing a simple .NET Core console application using C# in Visual Studio 2017. Visual Studio 2017 provides a full-featured development environment for building .NET Core applications. As long as the application doesn't have platform-specific dependencies, the application can run on any platform that .NET Core targets and on any system that has .NET Core installed.
Prerequisites
Visual Studio 2017 with the '.NET Core cross-platform development' workload installed. You can develop your app with .NET Core 2.1 or later versions.
For more information, see the Prerequisites for .NET Core on Windows topic.
A simple Hello World application
Begin by creating a simple 'Hello World' console application. Follow these steps:
- Launch Visual Studio 2017. Select File > New > Project from the menu bar. In the New Project* dialog, select the Visual C# node followed by the .NET Core node. Then select the Console App (.NET Core) project template. In the Name text box, type 'HelloWorld'. Select the OK button.
- Visual Studio uses the template to create your project. The C# Console Application template for .NET Core automatically defines a class,
Program
, with a single method,Main
, that takes a String array as an argument.Main
is the application entry point, the method that's called automatically by the runtime when it launches the application. Any command-line arguments supplied when the application is launched are available in the args array.The template creates a simple 'Hello World' application. It calls the Console.WriteLine(String) method to display the literal string 'Hello World!' in the console window. By selecting the HelloWorld button with the green arrow on the toolbar, you can run the program in Debug mode. If you do, the console window is visible for only a brief time interval before it closes. This occurs because theMain
method terminates and the application ends as soon as the single statement in theMain
method executes. - To cause the application to pause before it closes the console window, add the following code immediately after the call to the Console.WriteLine(String) method:This code prompts the user to press any key and then pauses the program until a key is pressed.
- On the menu bar, select Build > Build Solution. This compiles your program into an intermediate language (IL) that's converted into binary code by a just-in-time (JIT) compiler.
- Run the program by selecting the HelloWorld button with the green arrow on the toolbar.
- Press any key to close the console window.
Enhancing the Hello World application
Enhance your application to prompt the user for their name and display it along with the date and time. To modify and test the program, do the following:
- Enter the following C# code in the code window immediately after the opening bracket that follows the
static void Main(string[] args)
line and before the first closing bracket:This code replaces the contents of theMain
method.This code displays 'What is your name?' in the console window and waits until the user enters a string followed by the Enter key. It stores this string into a variable namedname
. It also retrieves the value of the DateTime.Now property, which contains the current local time, and assigns it to a variable nameddate
. Finally, it uses an interpolated string to display these values in the console window. - Compile the program by choosing Build > Build Solution.
- Run the program in Debug mode in Visual Studio by selecting the green arrow on the toolbar, pressing F5, or choosing the Debug > Start Debugging menu item. Respond to the prompt by entering a name and pressing the Enter key.
- Press any key to close the console window.
You've created and run your application. To develop a professional application, take some additional steps to make your application ready for release:
- For information on debugging your application, see Debug your .NET Core Hello World application using Visual Studio 2017.
- For information on developing and publishing a distributable version of your application, see Publish your .NET Core Hello World application with Visual Studio 2017.
Related topics
Instead of a console application, you can also build a class library with .NET Core and Visual Studio 2017. For a step-by-step introduction, see Building a class library with C# and .NET Core in Visual Studio 2017.
You can also develop a .NET Core console app on Mac, Linux, and Windows by using Visual Studio Code, a downloadable code editor. For a step-by-step tutorial, see Getting Started with Visual Studio Code.
Today, in this asp.net tutorial we will learn what is console application and how to create and run console application in visual studio 2010 with c# language.
The Console application is a application that run in a console output windows like c and c++ program. The Console application dose not have graphical user interface.
The Console application takes input and gives output at on command line output.
We can create console application in visual studio. Here we will learn to create console application in visual studio 2010 with c# language.
Open Visual Studio 2010 –> File –>> New Project –>> Console Application
In Visual studio create console application, we have to use Console class which is available with System namespace. System is the root namespace of console application.
Before, create console application we need to get basic ideas about Console.ReadLine(),Console.Write() and Console.WriteLine() Methods.
C# Importance Point
Console.ReadLine() – This method is used to read a string text from console windows. This will read input text from user at console windows and displays string at console windows when user press the enter key.
Console.Write() – write the text at console windows in same line.
Console.WriteLine() – Write the text at console windows and add a new line character at the end of the line.
Create Console application example in asp.net c#
In above visual studio home screen select file –> New Project option.
Select Console Application from dialog box and select Visual C# language and Give your first application name shows like below screen.
![Visual Studio For Mac Console Application C Visual Studio For Mac Console Application C](https://i.ytimg.com/vi/c0WClXPK8-0/maxresdefault.jpg)
After creating console application below is the first screen of console application.
Here, we have created one example for sum of two integer digit in console application. In this example we will input two integer values and get sum of that inputted values as output.
The c# code of sum example.
2 4 6 8 10 12 14 16 18 20 22 24 26 | usingSystem.Collections.Generic; usingSystem.Text; namespaceMyFirstConsoleApp classProgram staticvoidMain(string[]args) inta,b,sum; a=int.Parse(Console.ReadLine()); //OR //b = Convert.ToInt32(Console.ReadLine()); Console.WriteLine('The sum of {0} and {1} = {2}',a,b,sum); } |
Here is out put of console application example for sum of two integer values.
![Visual Studio For Mac Console Application C Visual Studio For Mac Console Application C](https://i.stack.imgur.com/iCXSQ.png)
I hope you will understand how to create console application in visual studio.