So I'm running into a problem with generic lists in C# such that:
var foo = new Dictionary<long, List<object>>();
foo.Add(123, new List<string>());
Gives the error: Cannot convert from System.Collections.Generic.List<string> to System.Collections.Generic.List<object>
Where as this works fine:
var foo = new Dictionary<long, object>();
foo.Add(123, new string());
My real use case would look like this:
var foo = new Dictionary<long, List<ISomeInterface>>();
foo.Add(123, new List<SomeClassA>());
foo.Add(345, new List<SomeClassB>());
Where both SomeClassA and SomeClassB implement ISomeInterface. Is this possible?
The idea being I can grab a list of ISomeInterface from the dictionary and iterate the list calling SomeMethod that is defined on ISomeInterface.