Project · Data
JSON task manager
Load and save tasks using JSON files.
All C# source files below are loaded together in the playground. Files written by a run live in its virtual directory.
Program.cs
using System.Text.Json;
var tasks = new List<TaskItem>
{
new("Write the README", true),
new("Add unit tests", false),
new("Ship to TestFlight", false),
};
File.WriteAllText("tasks.json", JsonSerializer.Serialize(tasks));
var saved = File.ReadAllText("tasks.json");
var loaded = JsonSerializer.Deserialize<List<TaskItem>>(saved) ?? new List<TaskItem>();
foreach (var task in loaded)
{
Console.WriteLine($"[{(task.Done ? "x" : " ")}] {task.Title}");
}
Console.WriteLine($"{loaded.Count(t => !t.Done)} of {loaded.Count} left");Models/TaskItem.cs
public sealed record TaskItem(string Title, bool Done);TaskManager.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>TaskManager</AssemblyName>
</PropertyGroup>
</Project>