CodeBlanks Logo Icon CodeBlanks

Putting it together

C# course · Beginner · Lesson 87/116

Build a working CLI app with a menu loop.

Putting it together

In the final lesson we will combine all pieces into a working CLI application. Inside Main we will place, in order: AddTask calls to add tasks, CompleteTask to update status, ListTasks to list tasks, and Console.WriteLine(tasks.Count) to print the total count.

The goal of this lesson is to turn separate pieces into a real flow. Real CLI applications have a menu loop; here we run a fixed sequence of commands directly to complete the project.

Menu loop concept

Real CLI applications run inside a menu loop: read a command from the user, call the matching method, and repeat until the user types exit. In this project we simulate the menu with fixed commands.

The flow follows this order: add tasks, list them, mark the wanted task as done, then print the total count. This structure is the skeleton of a real interactive application.

Exercise Combine the whole flow in Main

Write the whole flow into Main: AddTask(tasks, "Buy bread"), AddTask(tasks, "Buy milk"), CompleteTask(tasks, 0), ListTasks(tasks) and finally Console.WriteLine(tasks.Count).

Show example solution
In Main write in order AddTask(tasks, "Buy bread"); AddTask(tasks, "Buy milk"); CompleteTask(tasks, 0); ListTasks(tasks); Console.WriteLine(tasks.Count);.
Example solution:
using System;
using System.Collections.Generic;

class Task
{
    public string Title;
    public bool IsDone;
}

class Program
{
    static void AddTask(List<Task> tasks, string title)
    {
        tasks.Add(new Task { Title = title, IsDone = false });
    }

    static void ListTasks(List<Task> tasks)
    {
        foreach (Task t in tasks)
        {
            Console.WriteLine(t.Title);
        }
    }

    static void CompleteTask(List<Task> tasks, int index)
    {
        tasks[index].IsDone = true;
    }

    static void Main()
    {
        List<Task> tasks = new List<Task>();
        // Write the whole flow here
        AddTask(tasks, "Buy bread");
        AddTask(tasks, "Buy milk");
        CompleteTask(tasks, 0);
        ListTasks(tasks);
        Console.WriteLine(tasks.Count);
    }
}

Project complete

Congratulations! You reached the end of the five-lesson project. You wrote a to-do list CLI application; you declared the Task class and the AddTask, ListTasks and CompleteTask methods, and combined them all inside Main.

The structure you saw here — modeling data in a class, splitting operations into separate methods, and calling them in order from the main flow — is the foundation of real C# applications. Later you can extend this app with a menu loop, file saving, and console input.

Test yourself

  1. What does Count print after two adds?

    List<Task> tasks = new List<Task>();
    tasks.Add(new Task { Title = "Buy bread", IsDone = false });
    tasks.Add(new Task { Title = "Buy milk", IsDone = false });
    Console.WriteLine(tasks.Count);
    • 2
    • 0
    • 1
    • Buy bread
    Show answer

    2 — Correct. Two Add calls leave two tasks in the list; Count is 2.

  2. Match each method to its meaning

    AddTask
    Adds a task
    ListTasks
    Lists tasks
    CompleteTask
    Completes
    tasks.Count
    Task count
  3. ListTasks call

    List<Task> tasks = new List<Task>();
    AddTask(tasks, "Buy bread");
    ____
    
    Show answer
    List<Task> tasks = new List<Task>();
    AddTask(tasks, "Buy bread");
    ListTasks(tasks);
    

All lessons in Beginner