Time for action – making sure it works!

Follow the given steps:

  1. Copy the following code snippet as a query to LINQPad:
    string[] firstNames = {"Samuel", "Jenny", "Joyace", "Sam"};
    string[] matchingFirstNames = firstNames.Where(name=>name.StartsWith("Sa")).ToArray();
    matchingFirstNames.Dump("Name Array");
  2. Run the query. It will result in the following output:
    Time for action – making sure it works!

What just happened?

firstNames.Where(name=>name.StartsWith("Sa")) returns an IEnumerable<string>, and ToArray() converts it to a string[].

Thus, the result header shows the type of the returned result as a string[].


This one is similar to ToArray(). However, this one returns a List<T>

Get .NET 4.0 Generics now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.