Visual C# | Data structures exercise | Create a prioritised to-do list using a dictionary

This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.

Software ==> Visual C#  (79 exercises)
Version ==> Any version of C#
Topic ==> Data structures  (6 exercises)
Level ==> Average difficulty
Subject ==> C# training
Before you can do this exercise, you'll need to download and unzip this file (if you have any problems doing this, click here for help).

You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

In a new or existing project, create a new from called frmToDo.

Open the file called frmToDo.Designer.cs.  Replace the entire code with the contents of the text file in the above folder, then change the namespace in the first line to the name of your project.

When you've amended Program.cs accordingly, you should now be able to run this application:

The to-do form

You can type in anything you need to remember to do, and assign a date to it.

Create a private dictionary variable for the form with:

  • the key equal to the to do date; and
  • the value equal to the text description of the task.

Attach code to the add button so that you can add tasks to the dictionary.  Attach code to the display button to list out these tasks:

The final task list

Because you created a sorted dictionary object, the tasks will automatically appear sorted by the key (ie by the to-do date).


Note that you'll only be able to add one task on any given day, because you can't have duplicate key values in a dictionary.

Close down your application and any open files.

You can unzip this file to see the answers to this exercise, although please remember this is for your personal use only.
This page has 0 threads Add post