J
Jay B. Harlow [MVP - Outlook]
Scott,
Paul's blog indicates that CInt() is an alias for CType(, Integer).
As Cor suggests CType is the conversion operator, while DirectCast is the
cast operator.
To "confuse" the issue the Conversion operator can be used as the cast
operator, however I make every effort to avoid this, as VS.NET 2005 allows
operator overloading! With operator overloading we can use the Conversion
operator (CType) to convert our types as needed.
http://msdn2.microsoft.com/library/yf7b9sy7.aspx
For example we can define the conversion for a Rational (Fraction) type to &
from Double. Where the Rational type holds the Numerator & Denominator as
separate fields. CType will be able to use the overloaded conversion
operators, while I understand that Convert.To* will not.
Public Structure Rational
Private m_numerator As Integer
Private m_denominator As Integer
Public Shared Widening Operator CType(ByVal f As Rational) As Double
Return f.m_numerator / f.denominator
End Operator
Public Shared Narrowing Operator CType(ByVal d As Double) As Rational
Return New Rational(d)
End Operator
End Structure
Dim f As Fraction
Dim d As Double
f = CType(d, Fraction)
d = f
Hope this helps
Jay
Paul's blog indicates that CInt() is an alias for CType(, Integer).
As Cor suggests CType is the conversion operator, while DirectCast is the
cast operator.
To "confuse" the issue the Conversion operator can be used as the cast
operator, however I make every effort to avoid this, as VS.NET 2005 allows
operator overloading! With operator overloading we can use the Conversion
operator (CType) to convert our types as needed.
http://msdn2.microsoft.com/library/yf7b9sy7.aspx
For example we can define the conversion for a Rational (Fraction) type to &
from Double. Where the Rational type holds the Numerator & Denominator as
separate fields. CType will be able to use the overloaded conversion
operators, while I understand that Convert.To* will not.
Public Structure Rational
Private m_numerator As Integer
Private m_denominator As Integer
Public Shared Widening Operator CType(ByVal f As Rational) As Double
Return f.m_numerator / f.denominator
End Operator
Public Shared Narrowing Operator CType(ByVal d As Double) As Rational
Return New Rational(d)
End Operator
End Structure
Dim f As Fraction
Dim d As Double
f = CType(d, Fraction)
d = f
Hope this helps
Jay