Skip to main content
Published / updated

.NET, C#, and Development Setup

Before you start

You need: nothing. This is the first practical article in the track — it assumes no programming background.

You need installed: Visual Studio 2022 or later, with the .NET desktop development workload. This article shows you how to check, and what to do if it is missing.

Time: about 45 minutes, plus the practice.

New to all of this? Start here explains what an application is made of and introduces the school system every example uses. Any word you do not recognise is in the glossary.

Learning objective

Install Visual Studio, create and run a C# console application, and explain what happens between typing code and seeing output.

Topics

  • What .NET is, and how it differs from C#
  • SDK versus runtime
  • Creating a project in Visual Studio
  • Solutions, projects, and what each file does
  • Program structure — namespace, class, Main
  • Compile time versus run time
  • Reading and writing console data
  • Building the vocabulary the rest of the track uses

.NET and C#

Two different things, confused constantly.

What it is
C#The language — the words and grammar you write
.NETThe platform — the compiler, the runtime, and the class library your code uses

You write C#. The compiler turns it into an intermediate form. The runtime executes it. The class library supplies the ready-made types you build on — string, List<T>, DateTime, file access, networking.

Neither is useful without the other. VB.NET and F# also run on .NET, which is why the platform's name is not the language's name.

Modern .NET runs on Windows, Linux and macOS. The older Windows-only .NET Framework still runs many existing systems, and Track 04 covers reading that code. Everything here is modern .NET.

SDK and runtime

ContainsWho needs it
RuntimeJust enough to execute a compiled applicationAnyone running the software
SDKThe runtime, plus the compiler, the CLI and templatesAnyone writing it

Install the SDK. It includes the runtime, so you need only one download.

Installing Visual Studio installs the SDK for you. In the Visual Studio Installer, tick the .NET desktop development workload — that is the one this track needs. Add ASP.NET and web development now as well; Tracks 05 and 10 need it, and adding it later means running the installer again.

Checking what you have

  1. Help → About Microsoft Visual Studio shows the Visual Studio version.
  2. Tools → Get Tools and Features reopens the installer, where the Individual components tab lists every .NET SDK installed.
  3. The quickest check of all: start a new project (below) and look at the Framework dropdown. Whatever it offers is what you have.

If the Framework dropdown does not offer .NET 9.0, the SDK is missing rather than the project being wrong. Go back to the installer and add it.

Creating a project

  1. Open Visual Studio and choose Create a new project.
  2. Search for Console App. Pick the one whose tags read C#, Windows, Linux, macOS, then Next.
  3. Project name: SchoolConsole. Choose a location you can find again. Next.
  4. Framework: .NET 9.0. Leave the other boxes unticked. Create.
  5. Press Ctrl+F5 to run.

There are two Console App templates and picking the wrong one causes a confusing morning. The other is Console App (.NET Framework) — that is the old Windows-only platform from Track 04. If your new project shows App.config instead of a .csproj you can read, you picked that one. Delete it and start again.

Ctrl+F5, not F5.

KeyDoesResult for a console app
Ctrl+F5Start without debuggingWindow stays open: Press any key to continue
F5Start with debuggingWindow closes the instant the program ends

A beginner presses F5, sees a black window flash and vanish, and concludes nothing ran. Use Ctrl+F5 until you actually want to stop on a breakpoint — which is Article 09.

The buttons you will use daily

ActionWhereShortcut
Run without debuggingDebug menuCtrl+F5
Run with debuggingThe green ▶ buttonF5
Build onlyBuild → Build SolutionCtrl+Shift+B
Clean build outputBuild → Clean Solution
Show Solution ExplorerView → Solution ExplorerCtrl+Alt+L
Show the Error ListView → Error ListCtrl+\, E

Keep the Error List open. It is where the compiler tells you what is wrong, and a fresher who does not know it exists reads the same red squiggle for ten minutes instead.

Adding a .gitignore

Visual Studio adds one when you put the project under source control: Git → Create Git Repository, which writes a .gitignore covering bin/ and obj/ automatically.

Do that before your first commit. Adding it afterwards does not untrack files already committed — Track 16 covers why that is awkward to undo.

Project structure

What Solution Explorer shows you:

Solution 'SchoolConsole' (1 of 1 project)
└── SchoolConsole the project
├── Dependencies packages and framework references
└── Program.cs your code

What is actually on disk:

SchoolConsole/
├── SchoolConsole.sln the solution file
└── SchoolConsole/
├── SchoolConsole.csproj the project file
├── Program.cs your code
├── bin/ compiled output — never committed
└── obj/ intermediate build files — never committed

A solution is a container; a project is what builds. One solution can hold many projects — in Article 09 you add a second one for tests, and by Track 10 a real application has three or four. Solution Explorer hides bin/ and obj/ because you never touch them.

To see the project file: right-click the project → Edit Project File. Older Visual Studio versions made you unload the project first; .NET 9 opens it directly.

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

</Project>
ElementMeaning
OutputTypeExe runs; Library is referenced by other projects
TargetFrameworkWhich .NET version this builds against
NullableThe compiler warns where a null could reach a non-nullable reference
ImplicitUsingsCommon using directives are added automatically

Nullable is worth understanding early. With it enabled, string name promises never to be null and string? name admits it might be. The compiler then warns you before a NullReferenceException happens rather than after — and null failures are the most common runtime error a beginner hits.

bin/ and obj/ are generated. Delete them and the next build recreates them. They must never be committed.

Program structure

namespace SchoolConsole
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("NexCoding Academy — Student Console");
}
}
}
PartPurpose
namespaceGroups related types and prevents name collisions
classA container for data and behaviour
staticBelongs to the class itself, not to an instance
voidReturns nothing
MainThe entry point — where the runtime starts
string[] argsArguments passed on the command line

Main is the entry point. Exactly one method has that role, and the runtime calls it.

Modern C# allows top-level statements — a Program.cs with no visible class or Main:

Console.WriteLine("NexCoding Academy — Student Console");

The compiler generates the class and Main for you. It is convenient for a small script, but this track uses the explicit form, because every real project has classes and methods and hiding them makes the structure harder to learn.

Compile time and run time

Compile time is when the compiler reads your code. Run time is when the runtime executes it. Errors happen at both, and telling them apart is the first debugging skill.

int totalFees = "15000";
error CS0029: Cannot implicitly convert type 'string' to 'int'

A compile-time error means the program was never built. Nothing ran. The compiler names the file, the line and the rule.

string input = Console.ReadLine();
int rollNumber = int.Parse(input); // input was "NCA-2024-0012"
Unhandled exception. System.FormatException: The input string 'NCA-2024-0012' was not in a correct format.

A run-time error means the program built fine and failed while running. The compiler cannot know what a user will type.

There is a third kind neither catches:

decimal balance = account.TotalFees + account.PaidAmount; // should be minus

A logical error compiles, runs, and produces a wrong answer. No error appears anywhere — a student who has paid ₹12,000 shows a balance of ₹27,000 instead of ₹3,000. These are found by testing, not by tooling, and they are the most expensive kind.

Console input and output

using System;

namespace SchoolConsole
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("NexCoding Academy — Student Lookup");
Console.Write("Enter roll number: ");

string rollNumber = Console.ReadLine();

Console.WriteLine("Searching for " + rollNumber + "...");
Console.WriteLine($"Roll number entered: {rollNumber}");
}
}
}
MethodDoes
Console.WriteLineWrites, then moves to a new line
Console.WriteWrites without a new line — right for a prompt
Console.ReadLineReads one line of input, always as string
Console.ReadKeyWaits for a single key press

Console.ReadLine always returns a string. Even when the user types 85, you receive "85". Converting it is your job, and Article 02 covers doing it safely.

$"..." is string interpolation — the value of rollNumber is substituted where {rollNumber} appears. Prefer it to + concatenation for readability.

Vocabulary

These terms appear in every remaining article and in every job interview.

TermMeaning
CompileTranslating source code into a runnable form
RuntimeThe engine executing your compiled code
TypeThe kind of a value — int, string, Student
ObjectA specific instance created from a class
InterfaceA contract a class promises to fulfil
ExceptionA run-time error the program can catch and handle
TaskA unit of work that may complete later
DependencySomething your code needs supplied to it
NamespaceA named grouping of types
AssemblyThe compiled output — a .dll or .exe

Learn these as words you can define, not as words you recognise. Being able to say what an exception is separates a candidate who has read about C# from one who has written it.

Errors you will hit

What you seeCauseFix
A black window flashes and disappearsRan with F5Use Ctrl+F5
CS0029: Cannot implicitly convert type 'string' to 'int'Assigned text to a numberArticle 02 — parse it first
CS1002: ; expectedMissing semicolon, usually on the line above the one reportedAdd the ;
CS0103: The name 'Console' does not exist in the current contextMissing using System;, or the file is not in the projectAdd the using, or check Solution Explorer
Project has App.config and looks unfamiliarPicked Console App (.NET Framework)Delete it; create a Console App instead
The Framework dropdown has no .NET 9.0The SDK is not installedTools → Get Tools and Features → add it
Unable to copy file ... because it is being used by another processThe program is still running from a previous runClose the console window, then build again

Read the line number, then look at the line above it. A missing semicolon or brace is reported where the compiler noticed, which is usually one line later than where you made the mistake.

Common mistakes

  • Installing the runtime and expecting to build with it
  • Picking the .NET Framework template instead of the .NET one
  • Pressing F5 for a console app and thinking nothing ran
  • Committing bin/ and obj/
  • No .gitignore before the first commit
  • Assuming Console.ReadLine returns a number
  • Not distinguishing compile-time, run-time and logical errors
  • Closing the Error List and squinting at red squiggles instead
  • Disabling Nullable because the warnings are annoying

Practice

  1. Open Help → About Microsoft Visual Studio and note your version.
  2. Create SchoolConsole — File → New → Project → Console App, .NET 9.0.
  3. Run it with Ctrl+F5, then with F5. Note the difference in the window.
  4. In Solution Explorer, expand the solution, the project and Dependencies.
  5. Right-click the project → Edit Project File and identify all four elements from the table above.
  6. Put the project under source control — Git → Create Git Repository — then confirm bin/ and obj/ are ignored.
  7. Build → Clean Solution, check bin/ is emptied, then Ctrl+Shift+B and confirm it returns.
  8. Rewrite the generated Program.cs into the explicit namespace / class / Main form.
  9. Cause a compile-time error: assign "15000" to an int. Find it in the Error List, double-click the row, and confirm it jumps to the line.
  10. Cause a run-time error: int.Parse on a roll number like NCA-2024-0012.
  11. Cause a logical error: add PaidAmount instead of subtracting it, and confirm nothing warns you.
  12. Prompt for a roll number with Console.Write, read it, and echo it using interpolation.
  13. Write your own one-sentence definition of each of the ten vocabulary terms without looking.

Exercise 11 is the one to sit with. It is the error class that tooling cannot find for you.

You can now

  • Create a console project in Visual Studio and run it with Ctrl+F5
  • Tell the .NET template from the .NET Framework template, and say why it matters
  • Find your way around Solution Explorer, the Error List and the Build menu
  • Say what a solution is and what a project is
  • Explain what the .csproj file controls
  • Tell a compile-time error from a run-time one from a logical one
  • Read a value from the console and print it back
  • Define the ten vocabulary terms in your own words

Review questions

  1. What is the difference between C# and .NET?
  2. Why is installing the SDK enough, when the runtime is a separate download?
  3. What type does Console.ReadLine return, and why does that matter?
  4. Which error kind produces no message at all, and how do you find it?

Next: Types and operators