Я пытаюсь вернуть общий ValueCollection как ICollection. Из документов MSDN говорится, что Dictionary.ValueCollection реализует интерфейс ICollection. По какой-то причине, однако, я получаю сообщение об ошибке, когда ему нужно вывести ValueCollection как ICollection. Это пример кода, и ниже это ошибка, которую я получаю.не может преобразовать тип 'System.Collections.Generic.Dictionary <класс, класс> .ValueCollection в System.Collections.Generic.ICollection <T>
public ICollection<T> GetAllComponents<T>() where T : Component
{
Dictionary<Entity, Component>.ValueCollection retval = null;
if(!this.componentEntityDatabase.ContainsKey(typeof(T)))
{
Logger.w (Logger.GetSimpleTagForCurrentMethod (this), "Could not find Component " + typeof(T).Name + " in database");
return new List<T>();
}
Dictionary<Entity, Component> entityRegistry = this.componentEntityDatabase [typeof(T)];
retval = entityRegistry.Values;
return (ICollection<T>)retval;
}
ошибка:
Cannot convert type 'Systems.Collections.Generic.Dictionary<Entity,Component>.ValueCollection' to System.Collections.Generic.ICollection<T>
я это делаю не так? или есть альтернативный способ сделать это без копирования значений из Словаря?