当使用具有IEnumerable值的Dictionary时,无法从使用中推断出方法的类型参数

use*_*ser 1 c# generics

using System;
using System.Collections.Generic;

public class Test
{

    static List<T> F<T>(IDictionary<int, IEnumerable<T>> dictionary)
    {
        // ...
        return new List<T>();
        // ...
    }

    public static void Main()
    {
        var mydict = new Dictionary<int, LinkedList<int>>();
        F(mydict);
    }
}
Run Code Online (Sandbox Code Playgroud)

运行代码后的错误消息:

prog.cs(16,3): error CS0411: The type arguments for method `Test.F<T>(System.Collections.Generic.IDictionary<int,System.Collections.Generic.IEnumerable<T>>)' cannot be inferred from the usage. Try specifying the type arguments explicitly
Compilation failed: 1 error(s), 0 warnings
Run Code Online (Sandbox Code Playgroud)

Lee*_*Lee 5

IDictionary<TKey, TValue>是值类型不变,所以一个IDictionary<int, LinkedList<int>>是不是IDictionary<int, IEnumerable<int>>即使LinkedList<int>是一个IEnumerable<int>.