Property StatementProperty Statement
속성의 이름과 속성 값을 저장 하 고 검색 하는 데 사용 되는 속성 프로시저를 선언 합니다.Declares the name of a property, and the property procedures used to store and retrieve the value of the property.
구문Syntax
[ <attributelist> ] [ Default ] [ accessmodifier ]
[ propertymodifiers ] [ Shared ] [ Shadows ] [ ReadOnly | WriteOnly ] [ Iterator ]
Property name ( [ parameterlist ] ) [ As returntype ] [ Implements implementslist ]
[ <attributelist> ] [ accessmodifier ] Get
[ statements ]
End Get
[ <attributelist> ] [ accessmodifier ] Set ( ByVal value As returntype [, parameterlist ] )
[ statements ]
End Set
End Property
- or -
[ <attributelist> ] [ Default ] [ accessmodifier ]
[ propertymodifiers ] [ Shared ] [ Shadows ] [ ReadOnly | WriteOnly ]
Property name ( [ parameterlist ] ) [ As returntype ] [ Implements implementslist ]
요소Parts
attributelist
선택 사항입니다.Optional. 이 속성 또는
Get
또는Set
프로시저에 적용 되는 특성 목록입니다.List of attributes that apply to this property orGet
orSet
procedure. 특성 목록을 참조 하십시오.See Attribute List.Default
선택 사항입니다.Optional. 이 속성이 정의 된 클래스 또는 구조체에 대 한 기본 속성 임을 지정 합니다.Specifies that this property is the default property for the class or structure on which it is defined. 기본 속성은 매개 변수를 허용 해야 하며 속성 이름을 지정 하지 않고 설정 하 고 검색할 수 있습니다.Default properties must accept parameters and can be set and retrieved without specifying the property name. 속성을
Default
로 선언 하는 경우 속성 또는 속성 프로시저 중 하나에서Private
를 사용할 수 없습니다.If you declare the property asDefault
, you cannot usePrivate
on the property or on either of its property procedures.accessmodifier
Property
문과Get
및Set
문 중 하나 이상에 대 한 선택 사항입니다.Optional on theProperty
statement and on at most one of theGet
andSet
statements. 다음 중 하나일 수 있습니다.Can be one of the following:Access levels in Visual Basic을 참조하세요.See Access levels in Visual Basic.
propertymodifiers
선택 사항입니다.Optional. 다음 중 하나일 수 있습니다.Can be one of the following:
MustOverride Overrides
NotOverridable Overrides
Shared
Shadows
ReadOnly
WriteOnly
Iterator
name
필수 요소.Required. 속성의 이름입니다.Name of the property. Declared Element Names을 참조하세요.See Declared Element Names.
parameterlist
선택 사항입니다.Optional. 이 속성의 매개 변수를 나타내는 지역 변수 이름과
Set
프로시저의 가능한 추가 매개 변수를 나타내는 목록입니다.List of local variable names representing the parameters of this property, and possible additional parameters of theSet
procedure. 매개 변수 목록을 참조 하세요.See Parameter List.returntype
Option Strict
On
경우 필수입니다.Required ifOption Strict
isOn
. 이 속성에서 반환 하는 값의 데이터 형식입니다.Data type of the value returned by this property.Implements
선택 사항입니다.Optional. 이 속성이이 속성의 포함 클래스 또는 구조체에서 구현 하는 인터페이스에 각각 정의 된 하나 이상의 속성을 구현 함을 나타냅니다.Indicates that this property implements one or more properties, each one defined in an interface implemented by this property's containing class or structure. Implements 문을 참조 하세요.See Implements Statement.
implementslist
Implements
가 제공된 경우 필수입니다.Required ifImplements
is supplied. 구현 중인 속성의 목록입니다.List of properties being implemented.implementedproperty [ , implementedproperty ... ]
각
implementedproperty
에는 다음과 같은 구문과 요소가 있습니다.Eachimplementedproperty
has the following syntax and parts:interface.definedname
부분Part 설명Description interface
필수 요소.Required. 이 속성에 포함 된 클래스 또는 구조체에 의해 구현 된 인터페이스의 이름입니다.Name of an interface implemented by this property's containing class or structure. definedname
필수 요소.Required. interface
에서 속성을 정의 하는 데 사용할 이름입니다.Name by which the property is defined ininterface
.Get
선택 사항입니다.Optional. 속성이
ReadOnly
표시 되는 경우 필수입니다.Required if the property is markedReadOnly
. 속성의 값을 반환 하는 데 사용 되는Get
속성 프로시저를 시작 합니다.Starts aGet
property procedure that is used to return the value of the property. 자동 구현 속성에는Get
문이 사용 되지 않습니다.TheGet
statement is not used with auto-implemented properties.statements
선택 사항입니다.Optional.
Get
또는Set
프로시저 내에서 실행할 문 블록입니다.Block of statements to run within theGet
orSet
procedure.End Get
Get
속성 프로시저를 종료 합니다.Terminates theGet
property procedure.Set
선택 사항입니다.Optional. 속성이
WriteOnly
표시 되는 경우 필수입니다.Required if the property is markedWriteOnly
. 속성의 값을 저장 하는 데 사용 되는Set
속성 프로시저를 시작 합니다.Starts aSet
property procedure that is used to store the value of the property. 자동 구현 속성에는Set
문이 사용 되지 않습니다.TheSet
statement is not used with auto-implemented properties.End Set
Set
속성 프로시저를 종료 합니다.Terminates theSet
property procedure.End Property
이 속성의 정의를 종료 합니다.Terminates the definition of this property.
설명Remarks
Property
문은 속성의 선언을 소개 합니다.The Property
statement introduces the declaration of a property. 속성에는 Get
프로시저 (읽기 전용), Set
프로시저 (쓰기 전용) 또는 두 가지 모두 (읽기/쓰기)를 사용할 수 있습니다.A property can have a Get
procedure (read only), a Set
procedure (write only), or both (read-write). 자동 구현 속성을 사용 하는 경우 Get
및 Set
프로시저를 생략할 수 있습니다.You can omit the Get
and Set
procedure when using an auto-implemented property. 자세한 내용은 자동으로 구현된 속성을 참조하세요.For more information, see Auto-Implemented Properties.
Property
는 클래스 수준 에서만 사용할 수 있습니다.You can use Property
only at class level. 즉, 속성에 대 한 선언 컨텍스트 는 클래스, 구조체, 모듈 또는 인터페이스 여야 하며 소스 파일, 네임 스페이스, 프로시저 또는 블록일 수 없습니다.This means the declaration context for a property must be a class, structure, module, or interface, and cannot be a source file, namespace, procedure, or block. 자세한 내용은 선언 컨텍스트 및 기본 액세스 수준을 참조하세요.For more information, see Declaration Contexts and Default Access Levels.
기본적으로 속성은 공용 액세스를 사용 합니다.By default, properties use public access. Property
문에서 액세스 한정자를 사용 하 여 속성의 액세스 수준을 조정 하 고 필요에 따라 속성 프로시저 중 하나를 더 제한적인 액세스 수준으로 조정할 수 있습니다.You can adjust a property's access level with an access modifier on the Property
statement, and you can optionally adjust one of its property procedures to a more restrictive access level.
Visual Basic는 속성을 할당 하는 동안 매개 변수를 Set
프로시저에 전달 합니다.Visual Basic passes a parameter to the Set
procedure during property assignments. Set
에 대 한 매개 변수를 제공 하지 않으면 IDE (통합 개발 환경)에서 value
라는 암시적 매개 변수를 사용 합니다.If you do not supply a parameter for Set
, the integrated development environment (IDE) uses an implicit parameter named value
. 이 매개 변수는 속성에 할당 되는 값을 포함 합니다.This parameter holds the value to be assigned to the property. 일반적으로이 값을 개인 지역 변수에 저장 하 고 Get
프로시저가 호출 될 때마다 반환 합니다.You typically store this value in a private local variable and return it whenever the Get
procedure is called.
규칙Rules
혼합 액세스 수준.Mixed Access Levels. 읽기/쓰기 속성을 정의 하는 경우 필요에 따라
Get
또는Set
프로시저에 대해 다른 액세스 수준을 지정할 수 있습니다.If you are defining a read-write property, you can optionally specify a different access level for either theGet
or theSet
procedure, but not both. 이 작업을 수행 하는 경우 프로시저 액세스 수준이 속성의 액세스 수준 보다 더 제한적 이어야 합니다.If you do this, the procedure access level must be more restrictive than the property's access level. 예를 들어 속성을Friend
선언 하는 경우Set
프로시저Private
선언할 수 있지만Public
는 선언할 수 없습니다.For example, if the property is declaredFriend
, you can declare theSet
procedurePrivate
, but notPublic
.ReadOnly
또는WriteOnly
속성을 정의 하는 경우에는 각각 단일 속성 프로시저 (Get
또는Set
)가 모든 속성을 나타냅니다.If you are defining aReadOnly
orWriteOnly
property, the single property procedure (Get
orSet
, respectively) represents all of the property. 속성에 대해 두 개의 액세스 수준을 설정 하므로 프로시저에 대해 다른 액세스 수준을 선언할 수 없습니다.You cannot declare a different access level for such a procedure, because that would set two access levels for the property.반환 형식입니다.Return Type.
Property
문은 반환 하는 값의 데이터 형식을 선언할 수 있습니다.TheProperty
statement can declare the data type of the value it returns. 모든 데이터 형식 또는 열거형, 구조체, 클래스 또는 인터페이스의 이름을 지정할 수 있습니다.You can specify any data type or the name of an enumeration, structure, class, or interface.returntype
지정 하지 않으면 속성은Object
을 반환 합니다.If you do not specifyreturntype
, the property returnsObject
.구현이.Implementation. 이 속성이
Implements
키워드를 사용 하는 경우 포함 하는 클래스 또는 구조체에는Class
또는Structure
문 바로 다음에Implements
문이 있어야 합니다.If this property uses theImplements
keyword, the containing class or structure must have anImplements
statement immediately following itsClass
orStructure
statement.Implements
문은implementslist
에 지정 된 각 인터페이스를 포함 해야 합니다.TheImplements
statement must include each interface specified inimplementslist
. 그러나 인터페이스가Property
을 정의 하는 이름 (definedname
)은이 속성의 이름과 같을 필요가 없습니다 (name
).However, the name by which an interface defines theProperty
(indefinedname
) does not have to be the same as the name of this property (inname
).
동작Behavior
속성 프로시저에서 반환Returning from a Property Procedure.
Get
또는Set
프로시저가 호출 코드로 반환 되 면 호출 된 문 다음에 오는 문으로 실행이 계속 됩니다.When theGet
orSet
procedure returns to the calling code, execution continues with the statement following the statement that invoked it.Exit Property
및Return
문은 속성 프로시저에서 즉시 종료를 발생 시킵니다.TheExit Property
andReturn
statements cause an immediate exit from a property procedure. 프로시저의 어디에 든 많은Exit Property
및Return
문이 표시 될 수 있으며Exit Property
문과Return
문을 혼합할 수 있습니다.Any number ofExit Property
andReturn
statements can appear anywhere in the procedure, and you can mixExit Property
andReturn
statements.반환 값입니다.Return Value.
Get
프로시저에서 값을 반환 하려면 속성 이름에 값을 할당 하거나Return
문에 값을 포함 하면 됩니다.To return a value from aGet
procedure, you can either assign the value to the property name or include it in aReturn
statement. 다음 예에서는quoteForTheDay
속성 이름에 반환 값을 할당 한 다음Exit Property
문을 사용 하 여를 반환 합니다.The following example assigns the return value to the property namequoteForTheDay
and then uses theExit Property
statement to return.Private quoteValue As String = "No quote assigned yet."
ReadOnly Property QuoteForTheDay() As String Get QuoteForTheDay = quoteValue Exit Property End Get End Property
name
에 값을 할당 하지 않고Exit Property
를 사용 하는 경우Get
프로시저는 속성의 데이터 형식에 대 한 기본값을 반환 합니다.If you useExit Property
without assigning a value toname
, theGet
procedure returns the default value for the property's data type.Return
문은Get
프로시저 반환 값을 할당 하 고 프로시저를 종료 합니다.TheReturn
statement at the same time assigns theGet
procedure return value and exits the procedure. 다음 예제에서는이를 보여 줍니다.The following example shows this.Private quoteValue As String = "No quote assigned yet."
ReadOnly Property QuoteForTheDay() As String Get Return quoteValue End Get End Property
예제Example
다음 예제에서는 클래스의 속성을 선언 합니다.The following example declares a property in a class.
Class Class1
' Define a local variable to store the property value.
Private propertyValue As String
' Define the property.
Public Property Prop1() As String
Get
' The Get property procedure is called when the value
' of a property is retrieved.
Return propertyValue
End Get
Set(ByVal value As String)
' The Set property procedure is called when the value
' of a property is modified. The value to be assigned
' is passed in the argument to Set.
propertyValue = value
End Set
End Property
End Class