I am new to C # ... (.net 3.5)
I want the dictionary to contain two different types of objects, one of which is shared. while iterating through the list, I will call methods like add and clone. I tried it with base class and subclasses ....
namespace ConsoleApplication1 { class Element{ } class Child1 : Element { public Child1 Clone() { return clone; } } class Child2<T> : Element { public Child2<T> Clone() { return clone; } } class Program { static void Main(string[] args) { Dictionary<string, Element> d = new Dictionary<string, Element>(); d.Add("c1", new Child1()); d.Add("c2s", new Child2<string>()); d.Add("c2i", new Child2<int>()); foreach (KeyValuePair<string, Element> kvp in d) { Element e = kvp.Value.Clone(); } } } }
Is there a way or solution for my needs?
Thanks! Anna
source share