- Код: Выделить всё
Option Strict On
Option Explicit On
Imports System.ComponentModel
Imports System.Math
Imports System.Runtime.InteropServices
Public Interface _clsComplex
Sub Cmplx(ByVal Real As Double, ByVal Imag As Double)
ReadOnly Property Arg(ByVal X As Complex) As Double
ReadOnly Property Real(ByVal X As Complex) As Double
Function Add(ByVal X As Complex, ByVal Y As Complex) As Complex
End Interface
<ComClass(Complex.ClassId, Complex.InterfaceId, Complex.EventsId)> Public Class Complex
Implements _clsComplex
Public Const ClassId As String = "C7A24C46-32B3-43d5-9D51-3A8C075D01A0"
Public Const InterfaceId As String = "F28AD3A5-DD5B-44d8-A7F8-7671FC0C1E1D"
Public Const EventsId As String = "E683E5E6-E29D-48bc-A946-A43BA1FB5B4E"
Public Sub New()
MyBase.New()
End Sub
<Description("Присвоить комплексному числу вещественную Real и мнимую Imag части")> _
Public Sub Cmplx(ByVal Real As Double, ByVal Imag As Double) Implements _clsComplex.Cmplx
Re = Real
Im = Imag
End Sub
Public Shared ReadOnly Property Arg(ByVal X As Complex) As Double Implements _clsComplex.Arg
<Description("Вернуть аргумент комплексного числа")> _
Get
Return Atan2(X.Im, X.Re)
End Get
End Property
Public Shared ReadOnly Property Real(ByVal X As Complex) As Double Implements _clsComplex.Real
<Description("Вернуть вещественную Real часть комплексного числа")> _
Get
Return X.Re
End Get
End Property
<Description("Сложить два комплексных числа: Z=X+Y")> _
Public Shared Function Add(ByVal X As Complex, ByVal Y As Complex) As Complex Implements _clsComplex.Add
Dim Z As New Complex
Z.Re = X.Re + Y.Re
Z.Im = X.Im + Y.Im
Return Z
End Function
End Class
В таком синтаксисе VB выдает ошибку:
Methods or events that implement interface members cannot be declared 'Shared'.
Как нужно изменить код