C#/C# Concept
[C#] 메소드 오버로딩
군우
2018. 3. 15. 11:54
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | using System; namespace CSStudy_Overloading { class Program { static void Main(string[] args) { Console.WriteLine("Overloading Test"); Console.WriteLine("Abs(1): " + Abs(1)); Console.WriteLine("Abs(1.1): " + Abs(1.1)); Console.WriteLine("Abs(1.6666): " + Abs(1.6666)); Abs(1); } public static int Abs(int abs) { if (abs <= 0) { return -abs; } else return abs; } public static long Abs(long abs) { if (abs <= 0) { return -abs; } else return abs; } public static double Abs(double abs) { if (abs <= 0) { return -abs; } else return abs; } } } | cs |