11. ???

Печать
Рейтинг пользователей: / 0
ХудшийЛучший 

??? ? VB.NET

??????


? VB.NET ????????? ??????? ?? ????????, ????????????????? ???? ? ??????. ??????? ????????? ?? ????????, ?????????? ????????. ???? ??????? ?????????? ???????????? ???????. ?.NET ?????? ????? ??????????????? ?? ????? ?????.

????? ? ??? ???????????????? ???, ?????????? ???????????? ?????????????. ?????? - ??? ?????????? ????????????????? ????.

?????? ???????? ? ???? ????????? ? ???????, ??????? ????????? ? ?????????? ??????? ??????. ??? ????????? ? ??????? ?????????? ????????.

 

?????? ????????? ???

1. ????????????. ???????? ??????. ??? ?????? ? ??????? ???????????? ????????, ?????? ? ???????.

2. ????????????. ??????? ????? ???????? ???????? ? ?????? ?????? ???????? (???????). ?????-?????? ?????????? ???????, ?????-??????? - ???????????. ?????????? ???????? ??? ???????? ? ?????? ???????, ??????? ????? ???? ????????, ? ????? ????? ???????? ???????????? ???????? ??? ??????????. ???????????? ??????????? ? ??????? ????????? ????? Inherits. ????????:

Public Class Class1

Inherits ?????????????????

End Class

Visual Basic ?? ???????????? ????????????? ????????????. ? ??????? ?????? ????? ???? ?????? ???? ???????? (??????? ????? ??? ??????????). ?????? ???????????? ???????? ???? ????????? ???????, ?? ? ??????? ???????? ?????? ????? ???? ???? ??????? ?????.

3. ???????????. ?????? ????????? ???????? ????? ????? ?????????? ?????, ?? ?????????? ?? ?????? ??????????.

??????????? ???????????? ??? ?????? ???? ???????? ???? - Overridable ? Overrides. Overridable ???????????? ?? ?????? ???????? ??????, ????? ???????, ??? ?????? ??????? ????? ???????????????? ? ??????????? ???????. Overrides ???????????? ?? ?????? ???????????? ??????, ????? ???????, ??? ?????? ??????? ?????????????? ??????????????? ??????? ???????? ??????.

4. ??????????. ????????????? ???????? ? ?????????. ????? ???????? ? ?????? ?????? ??????? ? ??????, ????? ?? ????????? ??????????? ?????????

 

??? ???????? ?????? ?????? ?????? ??????? ?????????? ??????? ????? Add New Item / Class, ????? ???? ????????? ???? ?????? ??????.

??????????? ?????? ??????:

[???????_???????] Class ???_?????? ??? - ????? ??????????

[Inherits ???_??????-??????]

[Implements ?????_???????????]

...'?????? ??????? ?????? ???????? ? ?????? ?????? ??????

End Class

 

???????_???????:

 

??? ??????? ???????? ?????? ????? ????? ?????????? ?????? ?????????. ??? ????? ???????????? ?? ?? ???????? ?????, ????? MustInherit ? NotInheritable.

 

????????

???????? ?????????? ???????? ??????? ? ????????? ???????? ??????? ??? ?????? ??? ????????? ?????? ? ????? ???????.?????????? ???????? ?????? ????????? ??? ??? ? ???, ? ?????, ??? ???????, ???? ?????????? ??????? ??????? ? ??????? ????????. ???????? ????? ???? ?????????? ??? ?????? ??? ??? ??????.

??????? ????????? ?????????? ???????? ???????:

???????_??????? ???_???????? As ???_????????

????????: Public MyProperty As Integer

?????? ? ???????? ???????? ???????? ????? ????????? ???????:

MyClassl.MyProperty = 34

?????? ? ???? ?????? ?????????? ????????? ????????? ??????? ???????? ? ?????????? ????????? ???????????? ???????????? ?????? ????????.

??? ??????? ???? ??????? ????? ??????????????? ?????????? ???????, ??????? ????????? ??? ?????????? ????????? ???????. ????????? ??????? ????????????? ??? ?????????? ????????? ???? ??? ????????? ???????? ????????. ????????? ????????, ????????????? ????????? ????????:

???????_??????? Property ???_???????? As ???_????????

Get

'???, ??????????????? ??? ????????? ???????? ????????

???????????????? = ?????????????

End Get

Set (ByVal ???????? As ???_??????)

'???, ??????????????? ??? ????????? ???????? ? ????????

????????????? = ????????

End Set

End Property

??????????? Get ? ????????? ???????? ???????? ????????, ??????? ?????????? ???????? ???????? ??? ??? ??????. ???? ?????? ???????? ????? Get ? End Get, ?? ???????? ???????? ??????? ???????? ????? ??????????.

??????????? Set ???????? ?? ????????? ?????? ???????? ??? ????????. ???? ??????? ???????? ????? Set ? End Set, ?? ???????? ???????? ??????? ???????? ????? ??????????. ??? ?????????? ?????? ?? ??????????? Set ???????????? ???????? ????? Exit Property.

 

??????

?????? - ??? ????????? ??? ???????, ????????????? ???????. ?????? ?????????? ????????? ???????. ??? ?????? ?????? ??????? ??????????? ??????, ?????, ????? ?????, ???????? ??????. ????????: MyObject.Method1

?????? ????? ?????????? ??? ?? ?????????? ???????? ? ????????? ??? ??, ??? ????????? ? ???????.

?????? ????? ???? ????????? ? ?????????. ???????? ?????? ?????????? ????????? ??????, ? ???????? ???????????? ??? ?????????? ???? ??????. ?????? ????? New() - (??????????? ??????) ????????????? ?????????? ??? ???????? ?????? ???????. ??????????? ????? ????? ?????????.

? ????????????? ???????????? ????????????? ???. ????????????? ???????????? ???????? ?????????? ???? ????? (?????? ??????). ???? ??????? ?????????? ????? ? ??????? ?????? Finalize.

Visual Basic ????????? ?????????? ????????? ???????, ??????? ???? ? ?? ?? ???, ?? ????????? ????? ?????????? (?????????? ???????). ??? ?????? ?????? ????? ?????? ??? ?????, ????? ?????????? ???????? ???????? ? ??????? ????????.

??? ??????? ???????? ??? ??????, ???? ???????? ????? ???? ???????????, ?????????? ???????? ????? Public ?? Overridable. ????? Overrides ???????????? ??? ????????? ??????? ? ???????, ???? ??????? ????? ?????????? ?? ????? ??????? ? ??????? ????????? ????? ? ???? ?? ???????.

 

???????

??? ???? ????? ???????? ??????? ? ??????, ?????????? ??????????????? ???????? ?????? Event:

Public Event EventName(event parameters)

????? ?????????? ??????? ????????? ???????:

Public Event EventName(ByVal sender as Object, ByVal e as System.EventArgs)

????? System.EventArgs ?????????? ??????? ????? ?????????? ???????.

??? ????????? ??????? ?????? ?????? ???????????? ???????? RaiseEvent, ???????? ? ???????? ????????? ?????????? ??? ???????:

RaiseEvent EventName(????????? ???????)

?????? ??????? ? VB.NET ????????? ?? ?????? ????????? ????????? - ????????, ??????? ????? ???????? ????????? ??????. ??? ???????? ???????? ???????????? ???????? ????? Delegate.

Public Delegate Sub StringSubDelegate(ByVal aString As String)

 

?????????? ????????

????? ???????? ?????? ????? ????????? ?????? ???????? ????????? ?????????? ??????? ??????. ??? ????? ???????????? ??????????? ???????? ????? New. ?????????? ??? ??????? ???????? ??????????? ??????.

1. ??????? ??????????

Dim MyInstance As Object

MyInstance = New MyClass1()

??????? ????? ?????????? MyInstance ???? Object, ????? ????????? ??? ?????????? ??? ????????? ?????? MyClass1.

2. ?????? ??????????

????????? ?????????? ????? ??????????? ??? ?????????? ????????? ??????.

Dim MyInstance As MyClass1

MyInstance = New MyClass1()

??? ?????: Dim MyInstance As New MyClass1

????? ???????????? ?????? ????????.

 

??????????? ??????

??????????? ?????? ?? ????? ???????????????? ??????????, ? ???????????? ?????? ? ???????? ??????? ??? ?????? ???????. ??????:

Public MustInherit Class Number

...

Public MustOverride Function AsString() As String

End Class

???????? ????? MustInherit ????????, ??? ?????? ????? ???????????? ?????? ??? ???????? ??????????? ???????; ??????? ?????? Number ????????? ?????????.

??????? MustOverride ???????????? ??? ?????????????? ???????, ?????????? ??????? ??????????????? ???????????? ??????.

 

??????????

????????? ????? ??????????? ??? ??????????? ?????, ? ??????? ???? ?????? ?????????? ??????? ? ???????. ???? ? ??? ?? ????????? ????? ???? ?????????? ???????????? ??????????? ????????. ??? ???????? ?????????? ??????-???? ?????? ?????????? ????????? ?? ?? ????????? ?????, ? ?? ?????????, ????????????? ?????? ???????.

Public Interface IEmployee

???????? ???????, ???????, ???????

End Interface

 

Public Class Employee

Implements IEmployee

...

End Class

 

??? ????????? ?? ?????? ? ???? ?????? ????? ???????????? ???????? ????? MyClass. ??? ????????? ? ???????? ?????? - MyBase.