C#方法重載


方法重載
public class Penson {
//使用方法重載可以使用方法調用更加方便——方法名一樣的多個方法
//方法名必須一樣
//1.方法中的參數列表必須不同
//2.方法中的參數的個數不同
//在方法重載中,與返回值類型無關
public int sum (int a, int b) {
return a + b;
}
public float sum(float a, float b,float c)
{
return a + b + c;
}
}
class Program
{
static void Main(string[] args)
{
Penson p = new Penson();
Console.WriteLine(p.sum(5,8));
Console.WriteLine(p.sum(5.1f, 8.5f,9.4f));
}
}
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM