Console application review
Console application review
A complete small application combines a domain model, command processing and a presentation boundary. This milestone uses the rules from the preceding two lessons. The application stores tasks in memory and shows them in insertion order. It does not save to disk, support spaces within titles or accept concurrent users. These are explicit scope limits, not missing promises. The reference program uses a finite printable-ASCII transcript. For arbitrary external input, reject control characters, bound lengths and validate numeric-token grammar before parsing. A title containing a display separator such as : or | can make the summary ambiguous; the summary is not a serialization format. Completing an existing task is successful even if already complete; it does not duplicate the task.
First establish expected behavior, then run the same input after a refactor. The full reference program in example 1 can be placed in Program.cs of the provided console project template. No packages, network or interactive input are needed. All output below is predicted and remains unexecuted.
using System;using System.Collections.Generic;using System.Globalization;var board = new TaskBoard();string[] commands = { "list", "add 4 box", "add 4 duplicate", "add 0 bad", "add 9 label", "complete 8", "complete 4", "complete 4", "list", "list extra", "quit", "add 12 ignored" };foreach (string command in commands){ var parts = command.Split(' ', StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 1 && parts[0] == "quit") break; Console.WriteLine(Execute(board, parts));}static string Execute(TaskBoard board, string[] parts){ if (parts.Length == 1 && parts[0] == "list") return board.Summary(); if (parts.Length == 3 && parts[0] == "add" && TryId(parts[1], out int addId)) return board.Add(addId, parts[2]) ? "Added" : "Rejected"; if (parts.Length == 2 && parts[0] == "complete" && TryId(parts[1], out int completeId)) return board.Complete(completeId) ? "Completed" : "Missing"; return "Invalid command";}static bool TryId(string text, out int id) => int.TryParse(text, NumberStyles.None, CultureInfo.InvariantCulture, out id) && id > 0;sealed class WorkItem{ public int Id { get; } public string Title { get; } public bool Done { get; private set; } public WorkItem(int id, string title) { if (id <= 0 || string.IsNullOrWhiteSpace(title)) throw new ArgumentException("Invalid task"); Id = id; Title = title; } public void Complete() => Done = true;}sealed class TaskBoard{ private readonly List<WorkItem> items = new(); public bool Add(int id, string title) { if (id <= 0 || string.IsNullOrWhiteSpace(title)) return false; foreach (var item in items) if (item.Id == id) return false; items.Add(new WorkItem(id, title)); return true; } public bool Complete(int id) { foreach (var item in items) { if (item.Id != id) continue; item.Complete(); return true; } return false; } public string Summary() { if (items.Count == 0) return "Empty"; string result = ""; foreach (var item in items) { if (result.Length > 0) result += " | "; result += item.Id.ToString(CultureInfo.InvariantCulture) + ":" + item.Title + ":" + (item.Done ? "done" : "open"); } return result; }}TaskBoard owns storage and transitions; Execute maps validated tokens to operations and returns messages. The loop prints them and handles quit. The example exercises empty state, a duplicate, an invalid ID, a missing task, repeated completion and malformed list input.
Expected output (reasoned, not executed):
EmptyAddedRejectedInvalid commandAddedMissingCompletedCompleted4:box:done | 9:label:openInvalid commandBuild on the first example
using System;using System.Collections.Generic;var ids = new List<int> { 4 };bool accepted = TryAdd(ids, 4);Console.WriteLine(!accepted && ids.Count == 1 ? "PASS" : "FAIL");static bool TryAdd(List<int> ids, int id){ if (ids.Contains(id)) return false; ids.Add(id); return true;}This isolated regression check verifies both the returned rejection and the unchanged collection. The printed PASS is an expected result, not a recorded execution test.
Expected output (reasoned, not executed):
PASSApply the idea to another case
using System;var labels = new[] { "4:box:done", "9:label:open" };Console.WriteLine(Format(labels));Console.WriteLine(Format(Array.Empty<string>()));static string Format(string[] labels) => labels.Length == 0 ? "Empty" : string.Join(" | ", labels);String.Join places a separator between elements, never after the final element. Keep the explicit empty-state policy. This is a focused formatting alternative, not a replacement for the entire project.
Expected output (reasoned, not executed):
4:box:done | 9:label:openEmptyCommon mistakes and design choices
A success message alone does not prove that the correct task changed. Inspect the final state and failed commands. Do not expose the mutable internal list from TaskBoard: callers could bypass validation. For this small dataset linear searches and simple string concatenation are readable; larger workloads may justify indexing and more efficient formatting after measuring. Avoid adding persistence before specifying duplicate-ID and restart behavior.
Practice
Extend the project with remove <ID>. Define Missing for absent IDs and Removed for a successful deletion. Process add 2 tape, add 7 box, remove 2, remove 2, list. Refactor TaskBoard rather than directly modifying its private collection from Execute.
Use the manual practice task and knowledge check to verify your understanding. All examples target C# 14 / .NET 10; execution and ByteMind renderer support remain unverified.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Console application review — knowledge check
Apply the lesson concepts to the following scenarios.
What does list print before any task is added?
Which layer should remove a stored task?
Why check final state after a rejected command?
What happens when complete 4 is called twice after adding task 4?
Which limitation is deliberately retained?