Sqrt(convToDouble(add(mult(mReal, mReal), _
mult(mImaginary, mImaginary))))
Return convToT(mMagnitude)
End Get
End Property
Public Function CompareTo(ByVal other As Complex(Of T)) As Integer _
Implements IComparable(Of Complex(Of T)).CompareTo
Return Comparer(Of T).Default.Compare(Me.Magnitude, other.Magnitude)
End Function
End Structure
CHAPTER 12 n GENERICS 267
Public Class EntryPoint
Shared Sub Main()
Dim c As Complex(Of Int64) = New Complex(Of Int64)(4, 5, _
AddressOf MultiplyInt64, AddressOf AddInt64, AddressOf DoubleToInt64, _
AddressOf Int64ToDouble)
Console.WriteLine("Magnitude is {0}", c.Magnitude)
End Sub
Private Shared Sub DummyMethod(ByVal c As Complex(Of Complex(Of Integer)))
End Sub
Private Shared Function MultiplyInt64(ByVal val1 As Int64, _
ByVal val2 As Int64) As Int64
Return val1 * val2
End Function
Private Shared Function AddInt64(ByVal val1 As Int64, _
ByVal val2 As Int64) As Int64
Return val1 + val2
End Function
Private Shared Function DoubleToInt64(ByVal d As Double) As Int64
Return Convert.ToInt64(d)
End Function
Private Shared Function Int64ToDouble(ByVal i As Int64) As Double
Return Convert.ToDouble(i)
End Function
End Class
Now, the Complex(Of T) type can contain any kind of structure, whether it??™s generic or
not.
Pages:
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432