Creating a To-Do List App with C#


Developing a to-do list application in C# involves managing tasks, allowing users to add, edit, and remove items. In this example, we'll introduce the concept with a basic code snippet for managing a to-do list.


Sample C# Code for To-Do List


Here's a basic example of C# code for managing a to-do list:


using System;
using System.Collections.Generic;
class ToDoList
{
private List<string> tasks = new List<string>();
public void AddTask(string task)
{
tasks.Add(task);
}
public void RemoveTask(string task)
{
tasks.Remove(task);
}
public List<string> GetTasks()
{
return tasks;
}
}
class Program
{
static void Main()
{
var toDoList = new ToDoList();
toDoList.AddTask("Buy groceries");
toDoList.AddTask("Complete project");
toDoList.AddTask("Go for a run");
toDoList.RemoveTask("Complete project");
List<string> tasks = toDoList.GetTasks();
Console.WriteLine("To-Do List:");
foreach (var task in tasks)
{
Console.WriteLine("- " + task);
}
}
}

This code defines a `ToDoList` class that allows you to add, remove, and retrieve tasks. In a real to-do list app, you would create a user interface and potentially save tasks to a database or file for persistence.


Sample HTML To-Do List Form


Below is a simple HTML form for entering tasks and displaying the to-do list: