Time for action – let's go round and round with Repeat()

Follow the given steps:

  1. Copy the following as a query to LINQPad:
    Enumerable.Repeat<string>("World is not enough", 5)
              .ToList()
              .ForEach(c => Console.Write(c+Environment.NewLine));
  2. Run the query. This will display the following output:
    Time for action – let's go round and round with Repeat()

What just happened?

The Repeat() method works on a string type in the current query and the string to be repeated is passed as "World is not enough" and it has to be repeated five times.

Then ToList() converted it to a List<string> and then ForEach() is used to print the result.

Quantifier operators

In this section, we will discuss the following Quantifier operators: ...

Get .NET 4.0 Generics 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.