根据SortedList和SortedDictionary的文档,它们都实现了IReadOnlyCollection<KeyValuePair<TKey,TValue>>和IReadOnlyDictionary<TKey,TValue>。.net 4.5.2的文档版本也是如此,所以我的项目,针对C# 6.0 (维基百科说是.NET 4.6 ),应该包括在内。
根据VS 2015的编译器,他们没有。
我不能将一个SortedDictionary<int, string>传递给这个函数:
private static void funcIROCollKvp1 (IReadOnlyCollection<KeyValuePair<int, string>> i_rocollkvp)哪一个是错的?
下面是完整的代码:
private static void funcIROCollKvp1 (IReadOnlyCollection<KeyValuePair<int, string>> i_rocollkvp)
{
}
private static void Main ()
{
SortedList<int, string> listkvp = new SortedList<int, string> ();
SortedDictionary<int, string> dict = new SortedDictionary<int, string> ();
funcIROCollKvp1 (listkvp);
funcIROCollKvp1 (dict);
}参数1:无法从“Projects\testTKS_vs2015\test03\Program.cs(18,24,18,31):”转换为“'System.Collections.Generic.IReadOnlyCollection>‘”
参数1:无法从“Projects\testTKS_vs2015\test03\Program.cs(19,24,19,28):”转换为“'System.Collections.Generic.IReadOnlyCollection>‘”
发布于 2018-05-11 23:47:20
它并不是说你不能通过它们,它只是说它不知道如何通过。您可以手动将对象强制转换为IReadOnlyCollection。
funcIROCollKvp1((IReadOnlyCollection < KeyValuePair<int, string> > )listkvp);
funcIROCollKvp1((IReadOnlyCollection < KeyValuePair<int, string> > )dict);https://stackoverflow.com/questions/50300881
复制相似问题