Self-Review Exercises

  1. 21.1 Fill in the blanks in each of the following statements:

    1. A(n)               is used to iterate through a collection but cannot remove elements from the collection during the iteration.

    2. IEnumerator method               advances the enumerator to the next item.

    3. If the collection it references has been altered since the enumerator’s creation, calling method Reset will cause a(n)              .

    4. C# 6’s               directive allows access to a class’s static members without fully qualifying their names.

    5. The               statement implicitly obtains an enumerator via the GetEnumerator method and uses the enumerator’s MoveNext method and Current property to traverse the collection.

    6. A(n)               is a collection of key–value pairs.

    7.               allow you to define simple, anonymous methods—that is, methods that do not have names and that are defined where they are assigned to a delegate or passed to a delegate parameter.

    8. With               you specify how to iterate, not the library.

    9. With               the library determines how to iterate through a collection.

    10. In functional programming, a(n)               operation results in a new collection containing only the elements that satisfy a condition.

    11. In functional programming, a(n)               operation results in a new collection in which each element of the original collection is mapped to a new value (possibly of a different type). The new collection has the same number of elements as the collection that was mapped.

    12. In functional programming, a(n)               operation combines the elements of a collection into a single new value, typically using a lambda that specifies how to combine the elements.

    13. To initiate parallel processing with PLINQ, invoke IEnumerable<T> extension method               (from class ParallelEnumerable), which returns a(n)              .

  2. 21.2 State whether each of the following is true or false. If false, explain why.

    1. Functional programming’s filter, map and reduce operations correspond to the IEnumerable<T> extension methods Where, Select and Aggregate.

    2. A Hashtable stores key–value pairs.

    3. A class implementing interface IEnumerator<T> must define only methods MoveNext and Reset, and no properties.

    4. A SortedDictionary<K,V> can contain duplicate keys.

    5. A LinkedList<T> can contain duplicate values.

    6. Dictionary is an interface.

    7. Enumerators can change the values of elements but cannot remove them.

    8. With hashing, as the load factor increases, the chance of collisions decreases.

    9. Elements in an array must be sorted in ascending order before a BinarySearch may be performed.

    10. Class Array provides static method Sort for sorting array elements.

    11. A hash table is one way to implement a dictionary.

    12. The ?. operator determines whether an array or collection is null before accessing an element of the array or collection.

    13. A lambda expression begins with a parameter list and is followed by the => lambda operator and an expression that represents the lambda’s body.

    14. An expression lambda contains a statement block—one or more statements enclosed in braces ({})—to the right of the lambda operator.

    15. The parentheses surrounding a lambda’s parameter list are optional.

    16. A key aspect of functional programming is immutability—not modifying the data source being processed or any other program state, such as counter-control variables in loops. This eliminates common errors that are caused by modifying data incorrectly.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset