확장메소드는 클래스의 멤버를 확장시켜 준다. 확장메소드 지정은 모듈에서 지정해야 한다.
다음과 같은 Imports System.Runtime.CompilerServices 구문이 필요하다.

<Extension()>
Public Sub DisplayString(ByVal obj As String) As String
   console.writeline(obj)
End Function

위 구문은 해당 프로젝트에서 String 클래스의 메소드에 DisplayString이라는 확장 메소드를 추가한다.
String 개체.DisplayString로 사용할수 있다.

확장 메서드(Visual Basic)

+ Recent posts