为什么具有默认值枚举参数的泛型类的构造函数不能调用该类的受保护方法?

use*_*356 7 c# generics mono enums

一个简单的测试用例:

using System;

public class Test<T>
{
    public enum TestEnum
    {
        A,
        B
    }
    public Test (TestEnum a = TestEnum.A)
    {
        DoSomething ();
    }

    protected void DoSomething()
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

编译器(这是在Unity3D项目中使用单声道,.NET4.0目标)给出了在呼叫的错误Test()DoSomething().如果我删除默认参数TestEnum a,它就构建得很好.MonoDevelop想要调用默认参数TestEnum<>.A,但这不会编译,也不会TestEnum<T>.A(显然我不会期望这些工作,但使用MonoDevelop的自动完成,这是我得到的).

编辑:具体错误是: the name DoSomething doesn't exists in the current context

小智 1

正如评论中所说,这是一个编译器错误。

看来您的 Mono 开发环境并不真正喜欢 protected 关键字。

现在使用 {public,private}。