9.3 (Querying an Array of Invoice
Objects) Use the class Invoice
provided in the ex09_03
folder with this chapter’s examples to create an array of Invoice
objects. Use the sample data shown in Fig. 9.8. Class Invoice
includes four properties—a PartNumber
(type int
), a PartDescription
(type string
), a Quantity
of the item being purchased (type int
) and a Price
(type decimal
). Perform the following queries on the array of Invoice
objects and display the results:
Use LINQ to sort the Invoice
objects by PartDescription
.
Use LINQ to sort the Invoice
objects by Price
.
Use LINQ to select the PartDescription
and Quantity
and sort the results by Quantity
.
Use LINQ to select from each Invoice
the PartDescription
and the value of the Invoice
(i.e., Quantity * Price
). Name the calculated column InvoiceTotal
. Order the results by Invoice
value. [Hint: Use let
to store the result of Quantity
*
Price
in a new range variable total.
]
Using the results of the LINQ query in part (d), select the InvoiceTotal
s in the range $200 to $500.
Part number | Part description | Quantity | Price |
---|---|---|---|
83 |
Electric sander |
7 |
57.98 |
24 |
Power saw |
18 |
99.99 |
7 |
Sledge hammer |
11 |
21.50 |
77 |
Hammer |
76 |
11.99 |
39 |
Lawn mower |
3 |
79.50 |
68 |
Screwdriver |
106 |
6.99 |
56 |
Jig saw |
21 |
11.00 |
3 |
Wrench |
34 |
7.50 |
9.4 (Duplicate Word Removal) Write a console app that inputs a sentence from the user (assume no punctuation), then determines and displays the nonduplicate words in alphabetical order. Treat uppercase and lowercase letters the same. [Hint: You can use string
method Split
with no arguments, as in sentence.Split()
, to break a sentence into an array of string
s containing the individual words. By default, Split
uses spaces as delimiters. Use string
method ToLower
before calling Split
.]
9.5 (Sorting Letters and Removing Duplicates) Write a console app that inserts 30 random letters into a List<char>
. Perform the following queries on the List
and display your results: [Hint: Strings can be indexed like arrays to access a character at a specific index.]
Use LINQ to sort the List
in ascending order.
Use LINQ to sort the List
in descending order.
Display the List
in ascending order with duplicates removed.