7using System.Collections.Generic;
10using System.Threading.Tasks;
32 Console.WriteLine(
"Iterator Exercise");
38 Console.WriteLine(
" Iterating over keys only:");
39 var keyIterator = items.
GetKeys();
40 for (
string? item = keyIterator.Next(); item !=
null; item = keyIterator.Next())
42 Console.WriteLine(
" {0}", item);
45 Console.WriteLine(
" Iterating over values only:");
47 for (
string? item = valueIterator.Next(); item !=
null; item = valueIterator.Next())
49 Console.WriteLine(
" {0}", item);
52 Console.WriteLine(
" Iterating over all items:");
54 for (
ItemPair? item = itemIterator.Next(); item !=
null; item = itemIterator.Next())
56 Console.WriteLine(
" {0} = {1}", item.Key, item.Value);
59 Console.WriteLine(
" Done.");
Represents a key/value pair where the key and value are strings.
Example of using the Iterator Pattern in C#.
void Run()
Executes the example for the Iterator Pattern in C#.
Represents a container that offers up two kinds of iterators for the hardcoded contents.
IIterator< string > GetValues()
Retrieve an iterator over the "value" part of the data, where the data returned from the iterator is ...
IIterator< string > GetKeys()
Retrieve an iterator over the "key" part of the data, where the data returned from the iterator is a ...
IIterator< ItemPair > GetItems()
Retrieve an iterator over the data that returns an ItemPair object containing both key and value for ...
The namespace containing all Design Pattern Examples implemented in C#.