Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
547 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Software ==> | Visual C# (55 exercises) |
Topic ==> | Inheritance (5 exercises) |
Level ==> | Average difficulty |
Subject ==> | C# training |
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.
The aim of this exercise is to be able to create a sorted dictionary:
Create this so that we can later sort the tasks by date.
You should then be able to create new Task objects:
SingleTask t1 = new SingleTask(System.DateTime.Now.AddDays(7), "Give up smoking");
t1.Create();
SingleTask t2 = new SingleTask(System.DateTime.Now.AddDays(20), "Give up drinking");
t2.Create();
SingleTask t3 = new SingleTask(System.DateTime.Now.AddDays(11), "Audtion for BGT");
t3.Priority = SingleTask.TaskPriority.High;
t3.Create();
// cat needs feeding every week
SingleTask t4 = new RecurringTask(System.DateTime.Today.AddDays(6), "Feed the cat");
t4.Recurrence = SingleTask.TaskRecurrence.Week;
t4.Create();
You can then loop over the dictionary to get the tasks in sorted order:
// create dictionary of normal tasks
foreach (SingleTask t in SingleTask.tasks)
{
SortedTasks.Add(t.DateDue, t.Description);
}
// list out tasks in date order
string s = "";
foreach (KeyValuePair t in SortedTasks)
{
s += t.Key.ToString("dd MMM") + " - " + t.Value + "\n";
}
MessageBox.Show(s);
When this is all working, the exercise will then ask you to create a RecurringTask class. First things first!
Create a SingleTask class to hold the details of each task. You could include the following two enumerations:
public enum TaskPriority { Low, Medium, High }
public enum TaskRecurrence {
Once=0, Day=1, Week=7, Month=30, Year=365 }
By default, tasks should have Medium priority and Once task recurrence.
When code consuming the task calls the Create method, this should add the current instance of the class to a static list of type Task. You'll need to create a constructor and propertes to get the code shown at the start of this exercise to work!
When you've got all of the above working, add a RecurringTask class which inherits from the Task class. Include this in your code so that the new version allows you to add recurring tasks:
// cat needs feeding every week
Task t4 = new RecurringTask(System.DateTime.Today.AddDays(6), "Feed the cat");
t4.Recurrence = Task.TaskRecurrence.Week;
t4.Create();
When you add your 4 tasks (the 3 previous ones and this recurring one), you should see them sorted in date order:
The tasks you've created - recurring ones recur, as you'd expect!
Save and close any files, and give yourself another big pat on the back!
You can find other training resources for the subject of this exercise here:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2024. All Rights Reserved.