小编noo*_*oon的帖子

无法从'out T'转换为'out Component'

这里有一些不编译的C#代码,给出以下消息:

无法从'out T'转换为'out Component'

    public void Get<T>(out T c) where T : Component
    {
        m_components.TryGetValue(typeof(T), out c);
    }
Run Code Online (Sandbox Code Playgroud)

这是编译的代码:

    public void Get<T>(out T c) where T : Component
    {
        Component temp;
        m_components.TryGetValue(typeof(T), out temp);
        c = (T)temp;
    }
Run Code Online (Sandbox Code Playgroud)

我想知道为什么第一个代码无效,因为"where T:Component"明确指出T是Component类型.

谢谢

c#

9
推荐指数
2
解决办法
1892
查看次数

标签 统计

c# ×1