Methods With Same Name as Constructor - Why?

后端 未结 7 847
终归单人心
终归单人心 2020-12-01 16:09

Why is the following allowed:

public class Foo {
  public Foo() { ... }
  public void Foo() { ... }
}

Is there ever a valid reason for nami

相关标签:
7条回答
  • 2020-12-01 16:40

    I cannot see a valid reason for it.

    C# provides a compiler error - "Member Names Cannot Be The Same As Their Enclosing Type"

    It could be quite confusing, especially when using reflection to look at the composition of an object.

    0 讨论(0)
提交回复
热议问题