text
stringlengths
0
13.4k
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
static void Main is the entry point method of a C# program, and by
convention it's placed in a class (a type of code structure or module)
called Program . The using statement at the top imports the built-in
System classes from .NET and makes them available to the code in your
class.
From inside the project directory, use dotnet run to run the program.
You'll see the output written to the console after the code compiles:
dotnet run
13
Hello World in C#
Hello World!
That's all it takes to scaffold and run a .NET program! Next, you'll do the
same thing for an ASP.NET Core application.
14
Create an ASP.NET Core project
Create an ASP.NET Core project
If you're still in the directory you created for the Hello World sample,
move back up to your Documents or home directory:
cd ..
Next, create a new directory to store your entire project, and move into
it:
mkdir AspNetCoreTodo
cd AspNetCoreTodo
Next, create a new project with dotnet new , this time with some extra
options:
dotnet new mvc --auth Individual -o AspNetCoreTodo
cd AspNetCoreTodo
This creates a new project from the mvc template, and adds some
additional authentication and security bits to the project. (I'll cover
security in the Security and identity chapter.)
You might be wondering why you have a directory called
AspNetCoreTodo inside another directory called AspNetCoreTodo .
The top-level or "root" directory can contain one or more project
directories. The root directory is sometimes called a solution
directory. Later, you'll add more project directories side-by-side
with the AspNetCoreTodo project directory, all within a single root
solution directory.
15
Create an ASP.NET Core project
You'll see quite a few files show up in the new project directory. Once
you cd into the new directory, all you have to do is run the project:
dotnet run