LoginSignup
1
2

More than 5 years have passed since last update.

Genericクラスでデフォルト引数(enum)を持つメソッドの後に定義したメソッドはクラス内から見えなくなる

Posted at

あまり詳しくないのでそもそも問題があるコードなのかもしれませんが、
こんな感じのコードを書くとクラス内から一部のメソッドにアクセスできなくなります。

enumのデフォルト引数がよろしくないようです。

// Unityでエラーとなるコード(Ver4.6.3f1で確認)
public enum EnumType {
    Default,
    TypeA,
}

public class Hoge<T> {
    public void test() {
        Found();       //!< OK
        NotFound();    //!< error CS0103: The name 'NotFound' does not exist in the current context
    }


    public void Found() {
    }

    public void def(EnumType type = EnumType.Default) {
    }

    public void NotFound() {
    }
}

public class Test {
    public void test() {
        var a = new Hoge<int>();
        a.NotFound(); //!< 別クラスからならOK
    }
}
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2