Test Your Knowledge: Exercises

Exercise 21-1. For the first exercise in this chapter, we’re going to bring back the good old Box class from earlier in the book. It’s a quick and easy class, with Length, Width, and Height properties, and a quick method to display a box. Here’s the code for the class:

public class Box
{
    public int Length { get; set; }
    public int Width { get; set; }
    public int Height { get; set; }
    public void DisplayBox( )
    {
        Console.WriteLine("{0}x{1}x{2}", Length, Width, Height);
    }
}

Create a List of Box objects, at least five, with dimensions of whatever you like, and then use a LINQ query to extract all those boxes with a Length and Width greater than 3.

Exercise 21-2. Use LINQ to SQL, but not the Object Relational Designer, to retrieve all the orders from the Order Details table where the quantity ordered is greater than 100. (You’ll have to use a short type for the quantity, or else you’ll get an error.)

Exercise 21-3. Using the Object Relational Designer, find out which employees (first and last names) have serviced orders placed by the customer named Ernst Handel.

Get Learning C# 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.