Clonkex
Clonkex
CC#
Created by Clonkex on 9/5/2023 in #help
✅ Return List<Entity> from method with return type of List<T> where T : Entity
This is probably a dumb question, but why can't I do this?
public static readonly Dictionary<Type, List<Entity>> EntitiesByType = new();

public static List<T> GetEntitiesByType<T>() where T : Entity
{
if(EntitiesByType.TryGetValue(typeof(T), out var entities))
{
return entities;
}
return new();
}
public static readonly Dictionary<Type, List<Entity>> EntitiesByType = new();

public static List<T> GetEntitiesByType<T>() where T : Entity
{
if(EntitiesByType.TryGetValue(typeof(T), out var entities))
{
return entities;
}
return new();
}
I can't get my head around why this isn't allowed.
55 replies