EXERCISE TOPIC▼
C# 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# | Writing LINQ 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.
You can learn how to do this exercise if you attend one of more of the courses listed below!
Software ==> | Visual C# (79 exercises) |
Version ==> | Any version of C# |
Topic ==> | Writing LINQ (2 exercises) |
Level ==> | Relatively easy |
Classroom ==> | Fast track C# / Intermediate C# |
Online ==> | Fast track C# / Intermediate C# |
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:

Who'll be next? You can decide on the short-list.
Add code to the button so that it creates a string array of candidates (yours can be different!):
// create array of candidates
string[] candidates = { "Jeremy Corbyn", "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 show these names in the listbox using code like this:
// add these to the listbox
lstCandidates.DataSource = DoctorWhoCandidates.ToList();
A listbox won't accept an IEnumerable collection as its data source, so that's why you need to cast the results to a list. But you knew that, didn't you?
Test that when you click on the button, the names appear in the listbox!