代码片段1)不编译,我需要如果我由于某种原因想要按照原样进行测试,请在剪辑2) 中进行演员制作。但为什么编译器不能进行这种转换,例如铸造用于剪断3)将IList投射到IEnumerable
1)
static IDictionary<int, IEnumerable<int>> DoStuff()
{
var test = new Dictionary<int, IList<int>>() { { 1, new List<int>() { 1, 2 } } };
return test;
}
2)
static IDictionary<int, IEnumerable<int>> DoStuff()
{
var test = new Dictionary<int, IList<int>>() { { 1, new List<int>() { 1, 2 } } };
return test.ToDictionary(item => item.Key, item => (IEnumerable<int>)item.Value);
}
3)
static IEnumerable<int> DoStuff()
{
var test = new List<int>() { 1, 2 };
return test;
}