Skip to main content

How to write a Todo list app in 10 lines of code in pure C# [no dependencies]

· 2 min read
Krzysztof Krysiński
PixiEditor Creator & Core Developer

Show me the one programmer who didn't want to write its own todo list app. In this article, I'll show you how to do that in 10 lines of code, without any external dependencies. Yes, really.

Talk is cheap, show me the code

So, let's start with a new console app in .NET 5

New Console App

Let's give it a name

Todo App Name

Now select .NET 5

Select .NET 5

Great! Coding time

So, you ask me, how on earth, are you going to implement todo app in 10 lines of code?

The answer is simple, let me explain it step by step.

Let's start with defining your todo tasks.

BuyMilk();
BakeCookies();
TalkToYourGrandma();
WatchTv();
Code();

awesome, tasks defined. Now, go complete them, and after each completed task, come back to your pc and write a method. Like that

BuyMilk();
BakeCookies();
TalkToYourGrandma();
WatchTv();
Code();

void BuyMilk() { }

After you complete all of your tasks, your program will compile, which means, you have completed your todo list and app at the same time!

You can see which tasks are completed and which are not, in the real time.

Bonus points if your code editor highlights existing methods with green color, and undefined with red.

This is a final code

BuyMilk();
BakeCookies();
TalkToYourGrandma();
WatchTv();
Code();

void BuyMilk() { }
void BakeCookies() { } ;
void WatchTv() { }
void TalkToYourGrandma() { }
void Code() { }

Thank you for coming to my TED talk.