这段代码用分隔符打印字典键和值。
public static void DictionaryPrint<T ,U >(IDictionary<T,U> dictionary,string separator = " ")
{
foreach (KeyValuePair<T, U> pair in dictionary)
{
Console.WriteLine(pair.Key + separator + pair.Value);
}
}
问题:我可以写一些类似的东西
public static void DictionaryPrint<T, U>(IDictionary<T, U> dictionary, string separator = " ")
{
// this is for example , i now that dictionary doesn't have built-in ForEach mathod
dictionary.ForEach(KeyValuePair<T,U> kvp => Console.WriteLine(kvp.Key + separator + kvp.Value));
}
我需要类似 Java Stream Api 的东西。我试过 Linq 和 Enumerable 。