Exercise: Use LINQ to iterate over Doctor Who candidate names

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 Wise Owl course listed below!

Category ==> Visual C Sharp 2010  (65 exercises)
Topic ==> Writing LINQ  (1 exercise)
Level ==> Relatively easy
Course ==> Adv C# | Classes & LINQ
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, add the existing form from the folder shown above.  Make this the default form, so that this is what you see when you run your application:

Doctor Who form

This exercise was written shortly before the 12th Doctor Who was announced ...

Add code to the button so that it creates a string array of candidates (yours can be different!):

// create array of candidates

string[] candidates = { "Ed Milliband", "Sooty",

"Boris Johnson", "Adam Ant",

"Simon Cowell", "Oliver Owl" };

Add LINQ code to create a query expression to enumerate these names in alphabetical order, then for each name add it to the listbox using code like this:


Test that when you click on the button, the names appear in the listbox!

This page has 0 threads Add post