Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 12th, 2012  |  syntax: None  |  size: 0.39 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. List of different generic types, dynamic casting
  2. foreach(var entry in myList)
  3. {
  4.     var obj = (Sth<A, entry.Key>) entry.Value;
  5.     myMethod(obj); //This can have overloads for object, Sth<A,int>, Sth<A,string>,
  6.                    // etc. Generally, I need a correct type of obj here.
  7. }
  8.        
  9. foreach (KeyValuePair<A, object> entry in myList)
  10. {
  11.     dynamic value = entry.Value;
  12.     myMethod(value);
  13. }