.. highlight:: csharp ************ C# Library ************ Overview ======== The C# library for WebMapReduce is based on two user classes, and uses an iterator to manage the list of values passed to the reducer. The two classes that users must provide are:: namespace WMR { public class Mapper { public void map(string key, string value); } } :: namespace WMR { public class Reducer { public void reduce(string key, WmrIterator values); } } API === Class Wmr --------- :: namespace WMR { public class Wmr { public static void emit(string key, string value) { } } } The **Wmr** class contains a single method: public static void emit(string, string) Prints the two provided ``string`` objects to standard output separated by a tab character. Class WmrIterator ----------------- :: namespace WMR { public class WmrIterator : System.Collections.IEnumerable { public bool hasNext(); public System.Collections.IEnumerator GetEnumerator(); } } The **WmrIterator** class provides the list of values to the reducer. It also implements the Systems.Collections.IEnumerable interface so that it can be used with the ``foreach`` statement of the C# language, which means that one should rarely need to use its methods directly. public bool hasNext() Returns ``true`` when there is at least one additional value contained in the list (standard input) managed by the iterator. Otherwise returns ``false``. public Systems.Collections.IEnumerator GetEnumerator() Returns a C# enumerator that iterates through the input and can be used with ``foreach``. Example Usage ============= :: namespace WMR { public class Mapper { public void map(string key, string value) { string[] words = key.Split(' '); foreach (string word in words) { Wmr.emit(word, "1"); } } } } :: namespace WMR { public class Reducer { public void reduce(string key, WmrIterator values) { int sum = 0; foreach (string value in values) { sum += System.Convert.ToInt32(value); } Wmr.emit(key, System.Convert.ToString(sum)); } } }