私はC#のことは初めてです....(.net 3.5)
Dictionary に 2 つの異なるタイプのオブジェクトを保持させたいのですが、そのうちの 1 つはジェネリックです。リストを繰り返し処理しながら、add や clone などのメソッドを呼び出します。基本クラスとサブクラスで試してみました....
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();
}
}
}
}
私のニーズに対する方法または解決策はありますか?
ありがとう!アンナ