站内搜索: 请输入搜索关键词
当前页面: 图书首页 > From Java To C# A Developers Guide

From Java To C# A Developers Guide

[ directory ] Previous Section Next Section

7.7 Method overloading

There isn't much difference between method overloading in Java and in C#. You have multiple methods of the same name and return type in the same class.

Like Java

  • You cannot consider two methods with the same name and parameters but with a different return type as method overloading. For example, having

    public void DoThis (int j) {}
    

    and

    public int DoThis (int j) {return 0;}
    

    in the same class is illegal.

  • Constructors can be similarly overloaded. Like Java, you can invoke overloaded constructors from another constructor using the this keyword (see section 7.6).

    [ directory ] Previous Section Next Section