我相信这是可能的,而且我认为这很容易,只是我不知道在Google中询问问题的正确方式。我想做的是将type传递到一个方法中,并返回该类型的对象列表。类似于这样: public List<T> GetComponentsOfType(Type thisType) { return Components.OfType<thisType>().ToList(); } 当然,这段代码不能编译,因为我不知道我在做什么。
我猜你想传入类型参数,以便获取带有类型的列表: public List<T> GetComponentsOfType<T>() { return Components.OfType<T>().ToList(); }
method pass in type return c#
。虽然不是最好的,但还算不错。 - Patrick Hofman