WISE OWL EXERCISES
VISUAL C# EXERCISES
- Creating forms (4)
- Coding form events (1)
- Laying out your code (2)
- C# variables (4)
- Enumerations and constants (2)
- Conditions (2)
- Modular code (3)
- Arrays (2)
- Looping (2)
- Files and folders (3)
- Properties in C# (3)
- Using lists (3)
- Validating forms (6)
- Toolbars, menus and status bars (1)
- FileDialogs and StreamReaders (1)
- Debugging and trapping errors (1)
- Introduction to DataGridViews (1)
- DataGridView events (3)
- Complex DataGridViews (2)
- Creating classes (4)
- The form as a class (1)
- Data structures (6)
- Inheritance (5)
- Interfaces (2)
- Delegates and events (2)
- Writing LINQ (2)
- Advanced LINQ (2)
- Entity Frameworks (1)
- LINQ with Entity Frameworks (4)
- Grouping using LINQ (2)
- LINQ to SQL (2)
Visual C# | Interfaces exercise | Create an interface to treat room hires and dates the same
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 answer to the exercise will be included and explained if you attend the relevant Wise Owl course (sadly, only in the UK for now).
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.
Create a new project called Advanced_CSharp_exercises. Add the files in the folder above into a new project.
To do this, right-click on the project and choose Add --> Existing Item... Be careful to add all of the files, not just the ones of certain type.
Set the frmMeetings form to be the default one for the project, then run the project - you should now see that it gives you a very short list of invitations to send:
Each invitation has a description, an addresse and the text.
To start, have a quick look at the Venue, Customer, Tryst and RoomHire classes.
If you look at the code behind the form, you'll see that it also creates 3 venues, 3 customers, 2 trysts (dates between customers) and 2 room hires:
// create some venues
Venue RedLion = new Venue("Red Lion, High Street");
Venue CostaCoffee = new Venue("Costa Coffee, Market Street");
Venue CatholicChurch = new Venue(
"Church of Immaculate Conception, Church Road");
// create some people
Customer c1 = new Customer("Rita", "Brown");
Customer c2 = new Customer("Sue", "Jones");
Customer c3 = new Customer("Bob", "Smith");
// arrange some trysts between customers (Bob
// pessimistically meets 2 ladies)
Tryst t1 = new Tryst(c1, c3, RedLion,
new System.DateTime(2013, 11, 25, 11, 30, 0));
Tryst t2 = new Tryst(c2, c3, CostaCoffee,
new System.DateTime(2013, 11, 25, 12, 0, 0));
// now add separate room hires for speed
// dating (2 running simultaneously,
// although the Catholic Church one doesn't last as long)
DateTime whenStart = new System.DateTime(2013, 11, 22, 10, 0, 0);
RoomHire rh1 = new RoomHire(CostaCoffee,
RoomHire rh2 = new RoomHire(CatholicChurch,
Some code has been commented out:
// now create some happenings!
Your task is to add an interface called I_Happening which includes the following member:
// a happening must support a list of invitations
You'll need to amend the Tryst and RoomHire classes to implement this interface, and get them to support the required property.
Uncomment the code which is commented out. Add code to add one row to the data table for each request for each happening!
Run your program - you should get something like this:
Notice how each tryst has added two invitations: one for each person.
Close down any open files!