Creating Your First .NET Project: Complete C# Console App Tutorial
Learn how to create your first C# console application using the .NET CLI and Visual Studio. Follow a practical, step-by-step tutorial to build, run, and debug a Daily Task Tracker while understanding Program.cs, project files, user input, loops, methods, and error handling.
Creating Your First .NET Project: Complete C# Console App Tutorial
Starting your journey with .NET development becomes much easier when you build a real application instead of learning commands and concepts in isolation.
Your first project does not need a database, an API, or a complicated user interface. A simple console application is enough to understand how a .NET project is created, how C# code executes, how user input is processed, and how to identify and fix errors.
In this hands-on tutorial, you will build a Daily Task Tracker using C# and .NET. The application will allow users to add tasks, view their tasks, remove tasks, and exit the application through a simple menu.
By the end, you will understand the basic development workflow used when building larger .NET applications.
What You Will Learn
After completing this tutorial, you will be able to:
- Create a C# console application using the .NET CLI.
- Understand the basic structure of a .NET project.
- Write and execute C# code in
Program.cs. - Read input from users using
Console.ReadLine(). - Use variables, lists, loops, conditional statements, and methods.
- Build and run a .NET application from the terminal.
- Debug code using breakpoints and variable inspection.
- Identify common compilation and runtime errors.
- Understand the difference between building, running, and debugging an application.
1. What Is a Console Application in .NET?
A console application is a program that interacts with users through a text-based interface. It typically accepts input from the keyboard and displays output in a terminal or console window.
For example, a console application might:
- Calculate student grades.
- Track daily tasks.
- Manage simple expenses.
- Process files.
- Perform calculations.
- Test business logic before integrating it into a larger application.
Console applications are particularly useful when learning C# because you can focus on programming fundamentals without needing to build a graphical user interface.
The same fundamentals you learn here—variables, collections, methods, conditions, and loops—are also used in ASP.NET Core applications, background services, and other .NET projects.
2. Prerequisites: Install the .NET SDK
Before creating your first project, you need the .NET SDK installed on your computer.
The SDK includes the command-line tools, compiler, and other components required to create and build .NET applications.
Download it from the official .NET download page.
Choose an SDK version compatible with your learning goals and development environment. The latest SDK is not always necessary when working on an existing project, because that project may target a different framework.
Verify the Installation
Open a terminal, Command Prompt, or PowerShell and run:
dotnet --version
This command displays the active .NET SDK version.
To see all SDK versions installed on your machine, run:
dotnet --list-sdks
To list the installed .NET runtimes, run:
dotnet --list-runtimes
If the dotnet command is not recognized, verify that the SDK is installed correctly and that its installation directory is available through your system's PATH.
Important: The SDK and runtime serve different purposes. The SDK lets you create and build applications, while the runtime provides the environment needed to execute applications.
3. Create Your First .NET Console Project
There are two common ways to create a console application: using the .NET CLI or using Visual Studio.
For this tutorial, we will start with the .NET CLI because it helps you understand the commands used in real development workflows.
Step 1: Open a Terminal
Open PowerShell, Command Prompt, Windows Terminal, or the integrated terminal in your code editor.
Navigate to the directory where you want to store your projects.
For example:
cd Documents
The exact command depends on your current directory and operating system.
Step 2: Create the Project
Run the following command:
dotnet new console -n DailyTaskTracker
Let's break down this command:
| Command | Purpose |
|---|---|
dotnet | Invokes the .NET CLI. |
new | Creates a new project from a template. |
console | Selects the console application template. |
-n DailyTaskTracker | Sets the project name. |
The CLI creates a directory named DailyTaskTracker containing the initial project files.
Step 3: Open the Project Directory
Run:
cd DailyTaskTracker
You are now inside the project directory.
To see its contents, use:
dir
On Linux or macOS, you can generally use:
ls
You should see a project file named DailyTaskTracker.csproj and a C# source file named Program.cs.
Depending on the SDK version and project template, some additional files may also appear.
Step 4: Run the Default Application
Before changing anything, execute:
dotnet run
A newly generated console project typically displays:
Hello, World!
Congratulations! You have created and executed your first .NET console application.
The project template generated the initial code, the .NET tooling compiled the application when needed, and the application executed successfully.
4. Understand the Structure of Your First .NET Project
Before writing the actual application, let's understand the files that make up your project.
A typical console project looks like this:
DailyTaskTracker/
├── DailyTaskTracker.csproj
├── Program.cs
├── bin/
│ └── Debug/
│ └── net10.0/
└── obj/
└── Debug/
└── net10.0/
The exact folder names depend on the target framework and build configuration. For example, your project might target net8.0, net9.0, or another supported framework rather than net10.0.
Program.cs
Program.cs contains the C# code that starts your application.
In the default console template, you may see:
Console.WriteLine("Hello, World!");
Console.WriteLine() displays text and then moves to the next line.
You will replace this simple statement with the code for your Daily Task Tracker.
DailyTaskTracker.csproj
The .csproj file defines project settings, including the target framework and compiler options.
A simplified project file might look like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
The example targets .NET 10. Your generated project may use a different framework version.
Here is what the properties mean:
OutputType: Specifies that the project produces an executable application.TargetFramework: Identifies the framework the project targets.ImplicitUsings: Enables common namespace imports automatically.Nullable: Enables nullable reference type analysis.
You generally do not need to modify these settings for this tutorial.
The bin Folder
The bin folder contains compiled output generated by the build process.
For example, you may find compiled assemblies and runtime configuration files inside its framework-specific subdirectory.
The obj Folder
The obj folder contains intermediate build files and dependency information generated during restore and compilation.
Both folders are generated by the .NET tooling and are generally excluded from source control.
Key takeaway: You write application code in Program.cs, configure the project in the .csproj file, and let the .NET SDK generate the necessary build files.
5. Build a Practical C# Project: Daily Task Tracker
Now let's create a useful application rather than another program that only prints a message.
Our Daily Task Tracker will allow users to:
- Add a new task.
- View all existing tasks.
- Remove a task by its number.
- Exit the application.
For example, a user might add these tasks:
1. Complete C# fundamentals
2. Practice LINQ queries
3. Build an ASP.NET Core Web API
The program will display a menu and wait for the user to choose an operation.
To keep the first project beginner-friendly, the tasks will be stored in memory. They will disappear when the application exits. Later, you can extend this project to save tasks to a JSON file or a database.
Step 1: Open Program.cs
Open Program.cs in Visual Studio, Visual Studio Code, or your preferred code editor.
Remove the default Hello, World! statement.
Replace it with the following complete application.
Step 2: Write the Complete C# Code
var tasks = new List<string>();
bool isRunning = true;
while (isRunning)
{
Console.WriteLine("\n===== Daily Task Tracker =====");
Console.WriteLine("1. Add a task");
Console.WriteLine("2. View all tasks");
Console.WriteLine("3. Remove a task");
Console.WriteLine("4. Exit");
Console.Write("Choose an option: ");
string? choice = Console.ReadLine();
switch (choice)
{
case "1":
Console.Write("Enter your task: ");
string? task = Console.ReadLine();
if (!string.IsNullOrWhiteSpace(task))
{
tasks.Add(task.Trim());
Console.WriteLine("Task added successfully.");
}
else
{
Console.WriteLine("Task cannot be empty.");
}
break;
case "2":
if (tasks.Count == 0)
{
Console.WriteLine("No tasks available.");
}
else
{
Console.WriteLine("\nYour Tasks:");
for (int i = 0; i < tasks.Count; i++)
{
Console.WriteLine($"{i + 1}. {tasks[i]}");
}
}
break;
case "3":
if (tasks.Count == 0)
{
Console.WriteLine("There are no tasks to remove.");
break;
}
Console.Write("Enter the task number to remove: ");
string? input = Console.ReadLine();
if (int.TryParse(input, out int taskNumber)
&& taskNumber >= 1
&& taskNumber <= tasks.Count)
{
tasks.RemoveAt(taskNumber - 1);
Console.WriteLine("Task removed successfully.");
}
else
{
Console.WriteLine("Please enter a valid task number.");
}
break;
case "4":
isRunning = false;
Console.WriteLine("Thank you for using Daily Task Tracker!");
break;
default:
Console.WriteLine("Invalid option. Please choose between 1 and 4.");
break;
}
}
This is a complete, runnable console application.
Let's understand how it works before executing it.
6. Understand the C# Concepts Used in the Project
The Daily Task Tracker introduces several important C# programming concepts.
6.1 Variables
A variable stores a value that your program can use.
For example:
bool isRunning = true;
Here, isRunning is a Boolean variable. It can hold either true or false.
The application uses this variable to determine whether the menu should continue running.
6.2 Lists and Collections
The application stores tasks in a list:
var tasks = new List<string>();
List<string> is a collection that stores multiple strings and allows items to be added or removed dynamically.
When the user adds a task, the application executes:
tasks.Add(task.Trim());
The Trim() method removes leading and trailing whitespace from the entered task.
To count the tasks, the application uses:
tasks.Count
To remove a task by its zero-based index, it uses:
tasks.RemoveAt(taskNumber - 1);
Why subtract one?
Users usually number tasks starting from 1, but list indexes start from 0.
For example:
| User-visible task number | List index |
|---|---|
| 1 | 0 |
| 2 | 1 |
| 3 | 2 |
Subtracting one converts the user's task number into the corresponding list index.
6.3 The while Loop
The menu is controlled by this loop:
while (isRunning)
{
// Display menu and process user input.
}
A while loop repeats as long as its condition evaluates to true.
Initially, isRunning is true, so the menu appears.
When the user selects option 4, the program sets:
isRunning = false;
The loop then ends.
This approach lets the user perform multiple operations without restarting the application.
6.4 The switch Statement
The switch statement determines which operation to execute based on the user's choice.
switch (choice)
{
case "1":
// Add a task.
break;
case "2":
// View tasks.
break;
default:
// Handle an invalid option.
break;
}
Each case represents a possible input value.
The default section handles values that do not match the listed cases.
For example, entering 8 displays an error message because the application only supports options 1 through 4.
6.5 Reading User Input
The application reads keyboard input using:
string? choice = Console.ReadLine();
Console.ReadLine() reads a line of text from the console. It can return null, which is why the example uses the nullable annotation string?.
The application then checks the entered value using the switch statement.
This is a basic example of how programs receive and process user input.
6.6 Validating Input
A good application should not assume that users always enter valid data.
Consider this code:
if (!string.IsNullOrWhiteSpace(task))
{
tasks.Add(task.Trim());
}
The condition checks that the entered task is not null, empty, or composed entirely of whitespace.
For task removal, the application uses:
if (int.TryParse(input, out int taskNumber)
&& taskNumber >= 1
&& taskNumber <= tasks.Count)
{
tasks.RemoveAt(taskNumber - 1);
}
int.TryParse() attempts to convert the input into an integer without throwing a format exception when the input is invalid.
The additional conditions verify that the number corresponds to an existing task.
This is an example of input validation, an important practice in almost every type of application.
7. Run Your First Complete C# Application
Save Program.cs after adding the code.
Open the terminal in the project directory and execute:
dotnet run
You should see a menu similar to this:
===== Daily Task Tracker =====
1. Add a task
2. View all tasks
3. Remove a task
4. Exit
Choose an option:
Example: Add a Task
Enter:
1
The application asks for a task:
Enter your task:
Enter:
Learn C# fundamentals
The application responds:
Task added successfully.
The menu appears again because the while loop is still running.
Example: View Your Tasks
Enter:
2
The application displays:
Your Tasks:
1. Learn C# fundamentals
You can add more tasks and view them together.
Example: Remove a Task
If you have added multiple tasks, choose option 3.
For example:
Enter the task number to remove: 1
Task removed successfully.
The application removes the selected task and displays the menu again.
Example: Exit the Application
Enter:
4
The application displays:
Thank you for using Daily Task Tracker!
The loop ends, and the program terminates.
You have now created a complete interactive C# console application!
8. Build and Run: Understand the Difference
Beginners often use the words build and run interchangeably, but they represent different operations.
Build the Project
Execute:
dotnet build
The .NET SDK compiles the project and reports any compilation errors or warnings.
A successful build means the project compiled successfully for the selected configuration and target framework. It does not guarantee that every possible execution path is free from runtime errors.
Run the Project
Execute:
dotnet run
This command builds the project when necessary and starts the application.
Clean the Project
Execute:
dotnet clean
This removes generated build output associated with the selected configuration.
If you want to rebuild after cleaning, execute:
dotnet build
Compare the Commands
| Command | Purpose |
|---|---|
dotnet new console | Creates a console project. |
dotnet build | Compiles the project. |
dotnet run | Builds when necessary and executes the application. |
dotnet clean | Removes generated build output. |
dotnet restore | Resolves the project's NuGet dependencies. |
These commands form part of the standard workflow used when developing .NET applications.
9. Debug Your First .NET Project
Writing code is only one part of development. You also need to understand how to investigate unexpected behavior and fix errors.
Debugging allows you to execute your program under the control of a debugger, pause execution, inspect variables, and follow the program's logic.
You can debug C# applications using Visual Studio or Visual Studio Code with the appropriate C# development support.
Step 1: Set a Breakpoint
Open Program.cs.
Find this statement:
tasks.Add(task.Trim());
Click beside the line number in your editor to set a breakpoint.
A breakpoint tells the debugger to pause execution when the program reaches that line.
Step 2: Start Debugging
In Visual Studio, select Debug > Start Debugging or press F5.
In Visual Studio Code, open the Run and Debug view, select an appropriate C# launch configuration, and start debugging.
The exact setup depends on your editor and installed extensions.
Step 3: Enter a Task
When the application displays the menu, choose option 1 and enter a task.
When execution reaches the breakpoint, the debugger pauses before executing the selected statement.
Step 4: Inspect Variables
Inspect these variables:
tasks: The list containing previously added tasks.task: The text entered by the user.isRunning: The variable controlling the menu loop.
You can see the current values in the debugger's variable or watch panels.
Before the tasks.Add() statement executes, the newly entered task has not yet been added to the list.
Step over the statement and inspect tasks again. You should now see the new item.
Step 5: Continue Execution
Press F5 to continue running the application.
The program should display the success message and return to the menu.
Useful Debugging Shortcuts
| Shortcut | Common purpose |
|---|---|
F5 | Start or continue debugging. |
F9 | Toggle a breakpoint in Visual Studio. |
F10 | Step over the current statement in Visual Studio. |
F11 | Step into a method in Visual Studio. |
Shift + F5 | Stop debugging in Visual Studio. |
Keyboard shortcuts may vary by editor, operating system, and keymap. The table describes common Visual Studio shortcuts.
Debugging tip: When a program produces an unexpected result, inspect the values of variables at the point where the behavior occurs. This is often more effective than adding multiple print statements and guessing what went wrong.
10. Common Errors When Creating a .NET Project
You may encounter errors while following this tutorial. Understanding their causes will help you troubleshoot independently.
Error 1: dotnet Is Not Recognized
Possible cause: The .NET SDK is not installed, or the command-line executable is not available through your system's PATH.
Solution:
- Install the appropriate .NET SDK.
- Open a new terminal.
- Run
dotnet --version. - Verify the SDK installation if the command still fails.
Error 2: The Project Cannot Be Found
Possible cause: The terminal is not in the directory containing the .csproj file.
Solution:
Use cd to navigate to the project directory:
cd DailyTaskTracker
Then execute:
dotnet run
Error 3: Compilation Errors
Possible cause: A missing semicolon, mismatched braces, incorrect variable name, or another C# syntax error.
Solution:
Run:
dotnet build
Read the compiler output carefully. It usually identifies the file and line associated with the error.
Fix the code and build again.
Error 4: The Application Accepts Invalid Input
Possible cause: The code does not validate user input before processing it.
Solution:
Use appropriate checks such as:
int.TryParse(input, out int number)
For strings, consider:
string.IsNullOrWhiteSpace(input)
Validation should be appropriate to the operation being performed.
Error 5: Tasks Disappear After Restarting
Cause: The current application stores tasks only in memory.
The list exists while the program is running, but its contents are not automatically saved to permanent storage.
Solution:
As an extension, save tasks to a JSON file or a database. This introduces file handling or data persistence, which you can learn after understanding the current application.
11. Extend the Project: Challenges for Beginners
Once your Daily Task Tracker works, try improving it.
These exercises help you practise C# without simply copying an existing solution.
Challenge 1: Mark Tasks as Completed
Currently, users can add, view, and remove tasks.
Extend the application so users can mark a task as completed.
Requirements:
- Store a completion status for each task.
- Add a menu option to mark a task as completed.
- Display completed and pending tasks differently.
Concepts to practise: Classes, objects, properties, Boolean values, and conditional statements.
Challenge 2: Count Pending Tasks
Add a menu option that displays the number of tasks that are not completed.
For example:
Total tasks: 5
Completed tasks: 2
Pending tasks: 3
Concepts to practise: Collections, loops, and counting conditions.
Challenge 3: Save Tasks to a File
Modify the application so tasks are saved to a JSON file.
When the application starts, it should load previously saved tasks. When a task changes, the application should update the saved data.
Concepts to practise: File handling, JSON serialization, deserialization, and exception handling.
Challenge 4: Organize the Code into Methods
The current application contains most of its logic in one file.
Refactor the code into methods such as:
static void AddTask()
{
// Add task logic.
}
You will need to decide how those methods access and update the task collection.
Concepts to practise: Methods, parameters, return values, and code organization.
Challenge 5: Add Task Search
Allow users to search for tasks using a word or phrase.
For example, searching for C# could return:
1. Learn C# fundamentals
2. Build a C# console application
Concepts to practise: String methods, loops, and filtering collections.
These improvements gradually introduce concepts that are useful in larger C# applications.
12. Best Practices for Your First .NET Project
As you develop more applications, adopt these habits early:
- Use meaningful names: Prefer names such as
DailyTaskTrackerandtaskNumberover vague names such asxordata. - Keep code readable: Use consistent indentation and meaningful variable names.
- Validate input: Check user input before converting or processing it.
- Understand error messages: Read compiler output instead of immediately changing unrelated code.
- Build regularly: Compile your application after making significant changes.
- Use the debugger: Learn to inspect variables and step through execution.
- Use source control: Practise Git so you can track changes and recover earlier versions of your code.
- Avoid unnecessary complexity: Start with a working solution and introduce more advanced design patterns when they solve a real problem.
- Test different inputs: Try valid values, empty strings, invalid menu choices, and boundary cases.
- Build on what you learn: Add persistence, classes, unit tests, and more advanced features as your understanding grows.
13. Frequently Asked Questions
1. How do I create my first .NET project?
Install the .NET SDK, open a terminal, and execute dotnet new console -n MyFirstApp. Navigate to the new directory and run dotnet run to execute the generated console application.
2. What is the difference between a C# project and a .NET project?
A C# project typically uses C# source code and .NET tooling to produce an application or library. The .csproj file defines how the project is configured and built. C# can also target different frameworks and runtimes depending on the project configuration.
3. What does dotnet new console do?
It creates a console application from the .NET console project template. The generated project includes the files and configuration needed to begin writing and running C# code.
4. What is the purpose of Program.cs?
Program.cs contains the application's entry-point code. In a console application, it commonly contains the instructions that execute when the program starts.
5. Do I need Visual Studio to create a C# console application?
No. You can create, build, and run a console application using the .NET CLI and a suitable text editor. Visual Studio and Visual Studio Code provide additional editing and debugging features.
6. What is the difference between dotnet build and dotnet run?
dotnet build compiles the project. dotnet run builds the application when necessary and executes it.
7. Can I create an ASP.NET Core Web API after learning console applications?
Yes. Console applications provide a foundation in C#, variables, collections, methods, control flow, and debugging. You can apply those concepts when learning ASP.NET Core controllers, dependency injection, middleware, routing, and REST APIs.
8. Why does my console application lose its data when I close it?
In this tutorial, the task collection is stored in memory. Its contents are not saved automatically. To preserve data across restarts, you need a persistence mechanism such as a JSON file, SQLite, or SQL Server.
9. What is the easiest way to debug a C# application?
Set a breakpoint on a line of code, start the debugger, and inspect variable values as execution pauses. Step through statements to understand how the application behaves.
10. What should I learn after creating my first C# project?
Next, learn C# variables and data types, conditional statements, loops, methods, arrays and collections, classes and objects, exception handling, and debugging. Then progress to LINQ, asynchronous programming, Entity Framework Core, and ASP.NET Core.
Conclusion
Creating your first .NET project is an important milestone in becoming a .NET developer. By building the Daily Task Tracker, you have practised creating a project, writing C# code, handling user input, working with collections, running an application, and debugging its behavior.
The most important lesson is to build small, working applications while learning the fundamentals. Once you are comfortable with the console workflow, extend this project with classes, file storage, unit tests, and database integration.
Your next step: Learn C# variables, data types, conditions, loops, and methods in greater depth before moving on to object-oriented programming and ASP.NET Core development.
Last updated 10/26/2026
Your notes
Sign in to save personal notes on this topic — they'll sync across your devices.
Was this tutorial helpful?
Help us create more free learning resources. Learn more
