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 live online training, plus books, videos, and digital content from nearly 200 publishers.