Friend(Visual Basic)Friend (Visual Basic)
선언 된 프로그래밍 요소를 해당 선언이 포함 된 어셈블리 내 에서만 액세스할 수 있도록 지정 합니다.Specifies that one or more declared programming elements are accessible only from within the assembly that contains their declaration.
설명Remarks
대부분의 경우 클래스 및 구조체와 같은 프로그래밍 요소를 선언 하는 구성 요소 뿐만 아니라 전체 어셈블리에서 사용 해야 합니다.In many cases, you want programming elements such as classes and structures to be used by the entire assembly, not only by the component that declares them. 그러나 어셈블리 외부의 코드에서 액세스할 수 없도록 하는 것이 좋습니다 (예: 응용 프로그램이 소유 하는 경우).However, you might not want them to be accessible by code outside the assembly (for example, if the application is proprietary). 이러한 방식으로 요소에 대 한 액세스를 제한 하려는 경우 한정자를 사용 하 여 해당 요소를 선언할 수 있습니다 Friend
.If you want to limit access to an element in this way, you can declare it by using the Friend
modifier.
동일한 어셈블리로 컴파일되는 다른 클래스, 구조체 및 모듈의 코드 Friend
는 해당 어셈블리의 모든 요소에 액세스할 수 있습니다.Code in other classes, structures, and modules that are compiled to the same assembly can access all the Friend
elements in that assembly.
Friend
액세스는 응용 프로그램의 프로그래밍 요소에 대 한 기본 설정 수준 이며 Friend
인터페이스, 모듈, 클래스 또는 구조체의 기본 액세스 수준입니다.Friend
access is often the preferred level for an application's programming elements, and Friend
is the default access level of an interface, a module, a class, or a structure.
Friend
는 모듈, 인터페이스 또는 네임 스페이스 수준 에서만 사용할 수 있습니다.You can use Friend
only at the module, interface, or namespace level. 따라서 요소의 선언 컨텍스트는 Friend
소스 파일, 네임 스페이스, 인터페이스, 모듈, 클래스 또는 구조체 여야 합니다 .이는 프로시저일 수 없습니다.Therefore, the declaration context for a Friend
element must be a source file, a namespace, an interface, a module, a class, or a structure; it can't be a procedure.
참고
Protected Friend 액세스 한정자를 사용 하 여 클래스, 파생 클래스 및 클래스가 정의 된 동일한 어셈블리에서 클래스 멤버에 액세스할 수 있게 할 수도 있습니다.You can also use the Protected Friend access modifier, which makes a class member accessible from within that class, from derived classes, and from the same assembly in which the class is defined. 해당 클래스 내와 동일한 어셈블리의 파생 클래스에서 멤버에 대 한 액세스를 제한 하려면 Private Protected 액세스 한정자를 사용 합니다.To restrict access to a member from within its class and from derived classes in the same assembly, you use the Private Protected access modifier.
Friend
및 다른 액세스 한정자의 비교는 Visual Basic의 액세스 수준을 참조 하세요.For a comparison of Friend
and the other access modifiers, see Access levels in Visual Basic.
참고
다른 어셈블리를 friend 어셈블리로 지정 하 여로 표시 된 모든 형식 및 멤버에 액세스할 수 있도록 지정할 수 있습니다 Friend
.You can specify that another assembly is a friend assembly, which allows it to access all types and members that are marked as Friend
. 자세한 내용은 Friend 어셈블리를 참조하세요.For more information, see Friend Assemblies.
예제Example
다음 클래스는 한정자를 사용 하 여 Friend
동일한 어셈블리 내의 다른 프로그래밍 요소가 특정 멤버에 액세스할 수 있도록 합니다.The following class uses the Friend
modifier to allow other programming elements within the same assembly to access certain members.
Class CustomerInfo
Private p_CustomerID As Integer
Public ReadOnly Property CustomerID() As Integer
Get
Return p_CustomerID
End Get
End Property
' Allow friend access to the empty constructor.
Friend Sub New()
End Sub
' Require that a customer identifier be specified for the public constructor.
Public Sub New(ByVal customerID As Integer)
p_CustomerID = customerID
End Sub
' Allow friend programming elements to set the customer identifier.
Friend Sub SetCustomerID(ByVal customerID As Integer)
p_CustomerID = customerID
End Sub
End Class
사용량Usage
한정자는 다음 컨텍스트에서 사용할 수 있습니다 Friend
.You can use the Friend
modifier in these contexts:
Interface 문Interface Statement
Property StatementProperty Statement
Structure 문Structure Statement