Method overloading in C# (PlusMethod(int, int) and PlusMethod(double, double) sharing one name) is conceptually and syntactically identical to C++'s function overloading already covered in Topic_CPP — same rule ("as long as the number and/or type of parameters are different"), same motivating example structure (separately-named PlusMethodInt/PlusMethodDouble refactored into one overloaded PlusMethod) — reconfirming that C#'s object-oriented mechanics inherited directly from C++ rather than diverging, unlike the parameter-passing extensions (named arguments) covered in the immediately preceding chapter. [S1]
🧠 핵심 개념 (Core concepts)
Method overloading — multiple methods sharing the SAME name but differing in number and/or type of parameters. [S1]
Compiler resolves by signature — the compiler picks the correct overload based on the argument types/count supplied at the call site. [S1]
Motivation — avoids needing distinctly-named methods (PlusMethodInt, PlusMethodDouble) for functionally identical operations across different types. [S1]
📖 세부 내용 (Details)
Before overloading (distinct names): static int PlusMethodInt(int x, int y) { return x + y; } static double PlusMethodDouble(double x, double y) { return x + y; }. [S1]
After overloading (shared name): static int PlusMethod(int x, int y) { return x + y; } static double PlusMethod(double x, double y) { return x + y; } — called as PlusMethod(8, 5) (resolves to int version) and PlusMethod(4.3, 6.26) (resolves to double version). [S1]
General signature examples cited: int MyMethod(int x), float MyMethod(float x), double MyMethod(double x, double y) — all valid overloads of MyMethod. [S1]
⚖️ 모순 및 업데이트 (Contradictions & updates)
C++의 함수 오버로딩과 개념·문법이 동일: 매개변수 개수/타입만 다르면 같은 이름을 여러 메서드가 공유할 수 있다는 규칙과 예제 구성 방식이 Topic_CPP의 Function Overloading 챕터와 차이가 없다는 점이 확인됨 — 이전 챕터(Named Arguments)의 C/C++ 대비 확장과는 달리, 오버로딩은 C++에서 그대로 계승된 메커니즘. [S1]
🛠️ 적용 사례 (Applied in summary)
서로 다른 이름의 두 메서드(PlusMethodInt/PlusMethodDouble)를 하나의 오버로드된 PlusMethod로 리팩터링하는 예제가 원문에서 직접 실전 활용 사례로 제시됨. [S1]
💻 코드 패턴 (Code patterns)
Overloading the same method name for different parameter types (C#):
staticintPlusMethod(intx,inty){returnx+y;}staticdoublePlusMethod(doublex,doubley){returnx+y;}staticvoidMain(string[]args){intmyNum1=PlusMethod(8,5);// resolves to int versiondoublemyNum2=PlusMethod(4.3,6.26);// resolves to double version}
✅ 검증 상태 및 신뢰도
상태: draft
검증 단계: conceptual
출처 신뢰도: B (W3Schools — widely used educational reference, not a primary standards body)