GenericStuff

Published Thu, Apr 28 2005 23:31 | girishb
Finally, I can get back to writing stuff like this. :)

public class GenericStuff
{
    public delegate void Function<K,V>(K k,V v);

    public static void Print<K,V>(K k, V v){
        Console.WriteLine("Key: " + k.ToString() + " Value: "+ v.ToString());
    }
    
    public static void ForEachIfValue<K,V>(IDictionary<K,V> d, V value, Function<K,V> action) {
        foreach (KeyValuePair<K,V> kvp in d){
            if (kvp.Value.Equals(value)){
                action(kvp.Key,kvp.Value);
            }
        }
    }

    public static void ForEach<K,V>(IDictionary<K,V> d,Function<K,V> action) {
        foreach (KeyValuePair<K,V> kvp in d){
            action(kvp.Key,kvp.Value);
        }
    }
    
    public static void ForEach<K>(ICollection<K> d, Action<K> action) {
        foreach (K key in d){
            action(key);
        }
    }
}

Search

This Blog

Tags

Community

Archives

Personal

Blog roll

Syndication

Email Notifications