Professional Documents
Culture Documents
C# Tutorial: Hello World
C# Tutorial: Hello World
Hello World
To create a simple Hello World program in Visual Studio, open
File, select New, and select Project. Select Visual C# from the
left pane and select Console Application. The IDE will display
lines of codes. Within the codes, locate the inner most part of
the syntax which is here:
static void Main(string[] args)
{
namespace YeeTutorial
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello Philippines!");
Console.ReadLine();
}
}
}
Options:
-h|--help Display help.
--info Display .NET information.
--list-sdks Display the installed SDKs.
--list-runtimes Display the installed runtimes.
path-to-application:
The path to an application .dll file to execute.
Got an error?
If you receive a 'dotnet' is not recognized as an internal or
external command error, make sure you opened a new command
prompt. If you can't resolve the issue, use the I ran into an
issue button to get help fixing the problem.
Program.cs
using System;
namespace myApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
Got an error?
If you receive a message similar to Template "Console
Application" could not be created. Access to the path
'C:\Windows\System32\myApp' is denied., change your current
directory to one where you have permissions to create a new
folder and try to run the command again. If you can't resolve the
issue, use the I ran into an issue button to get help fixing the
problem.
dotnet run
Then, add the highlighted line after the code that prints "Hello
World!", like the following:
Program.csCopy
using System;
namespace myApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Console.WriteLine("The current time is " + DateTime.Now);
}
}
}
dotnet run
Hello World!
The current time is 11/10/2020 8:00:00 AM
Parts of a program
Arguments
Arguments are the data being passed into the method (normally
seen inside the open and close parenthesis, like this one:
Console.WriteLine("Hello World");
24:38
Path: C:\Users\Yee\source\repos