Skip to content

CSharp Basics Console InputOutput

Joe Care edited this page Dec 22, 2025 · 1 revision

C# Basics: Console Input and Output

This lesson focuses on getting input from the user and printing output to the console.

Related wiki pages:

  • Hello World: Lesson19.12.2025.md (to be renamed)
  • Basics: CSharp-Basics-ConsoleWriteLine-DateTime.md

Official docs:


1. Simple input/output example

using System;

namespace CSharpTutorial
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to C# 101!");

            Console.Write("Please enter your name: ");
            string? userInput = Console.ReadLine();

            if (!string.IsNullOrEmpty(userInput))
            {
                Console.WriteLine("Hello, " + userInput + "!");
            }
            else
            {
                Console.WriteLine("You pressed Enter without typing a name.");
            }
        }
    }
}

Key APIs:

  • Console.WriteLine – prints text plus newline
  • Console.Write – prints text without newline
  • Console.ReadLine – reads a full line of input

2. Running with the .NET SDK

See the instructions in Lesson19.12.2025.md for creating and running a console project.


3. Next steps

  • Extend this example to read a number and use int.TryParse.
  • Combine with conditions and loops from other lessons in this wiki.

Clone this wiki locally