(C#) 12. 코드의 흐름 제어 (overloading)
overloading
(Overloading)
- 최초 작성일: 2021년 3월 21일(월)
##
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
44
45
46
47
48
using System;
namespace overloading
{
class Program
{
// 함수 이름의 재사용
static int Add(int a, int b)
{
Console.WriteLine("Add int 호출");
return a + b;
}
static int Add(int a, int b, int c)
{
Console.WriteLine("Add int 호출");
return a + b + c;
}
static float Add(float a, float b)
{
Console.WriteLine("Add float 호출");
return a + b;
}
static double Add(int a, int b, int c = 0, float d = 1.0f, double e = 3.0)
{
Console.WriteLine("Add int 호출");
return a + b + c + d + e;
}
static void Main(string[] args)
{
int ret = Program.Add(2, 3);
Console.WriteLine(ret);
int ret2 = Program.Add(2, 3, 4);
Console.WriteLine(ret2);
float ret3 = Program.Add(2.0f, 3.0f);
Console.WriteLine(ret3);
double ret4 = Program.Add(1, 2, d: 2.0f);
Console.WriteLine(ret4);
}
}
}
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.