메서드 그룹 (Method Group)
메서드 집합의 이름. 여러 개의 오버로드를 모두 포함한 것. 예를 들어 ToString 메서드는 `ToString()`, `ToString(string formant)` 등 여러 오버로드를 가지고 있는데, 여기서 ToString 그 자체를 메서드 그룹이라고 한다.
메서드 시그니처 (Method Signature)
메서드의 이름과 매개변수 타입 정보를 포함 하는 것을 의미한다.
void PrintMessage(string message); // 시그니처: PrintMessage(string)
void PrintNumber(int number); // 시그니처: PrintNumber(int)
메서드 시그니처는 오버로딩을 구분하는 기준이 된다. C#에서는 반환형 타입은 메서드 시그니처의 일부가 아니다. 메서드의 이름과 해당 매개변수의 타입만(매개변수 이름은 제외) 시그니처의 일부가 된다.
그러나 델리게이트와 델리게이트가 가리키는 메서드 간의 호환성을 결정할 때는 반환 타입도 시그니처의 일부로 고려된다.
delegate int MyDelegate(); // 반환 타입이 `int`
class Program
{
static int GetNumber() => 42; // (O) 호환됨 (int 반환)
static void PrintNumber() => Console.WriteLine(42); // (X) 델리게이트와 호환되지 않음 (void 반환)
static void Main()
{
MyDelegate d = GetNumber; // (O) 가능
// MyDelegate d2 = PrintNumber; // (X) 컴파일 오류
}
}
참고 자료
- https://stackoverflow.com/questions/886822/what-is-a-method-group-in-c
- https://www.csharpstudy.com/latest/CS11-improved-method-group.aspx
- https://learn.microsoft.com/ko-kr/dotnet/csharp/programming-guide/classes-and-structs/methods
- https://stackoverflow.com/questions/8808703/method-signature-in-c-sharp
'C#' 카테고리의 다른 글
[C#] 공변성과 반공변성의 개념 설명과 Generic의 out과 in 키워드에 대하여 (0) | 2025.03.04 |
---|---|
[C#] Public 필드와 프로퍼티 (0) | 2024.12.20 |
[C#] Delegate, EventHandler 그리고 구조에 대한 고민 (0) | 2024.12.06 |
[C#] 제너릭 메소드 (0) | 2024.10.06 |
[C#] CS0273에러 accessor must be more restrictive than the property or indexer (1) | 2024.09.25 |