Explicitly Implicit

Here's a VB.NET quirk, to get the ball rolling:

In C#, you can say this:

Size size;

SizeF sizeF;

size = new Size(100, 100);

sizeF = size;

That's because the Size type has a Type Conversion defined for SizeF.

The documentation says:

In Visual Basic, you can use the conversion operators defined by a type, but you cannot define your own.

Here's an attempt to do the same thing in VB.NET:

Dim size As New Size(100,100)

Dim sizeF As SizeF

'These do not work - even with Option Strict Off

'sizeF = size

'sizeF = CType(size, SizeF)

'Call op_Implicit explicitly - works!

sizeF = Size.op_Implicit(size)

'Hey - fancy VB feature...

With size

    sizeF = New SizeF(.Width, .Height)

End With

Is this behaviour the same in VB.NET 2003?

1 Comment

  • If I'm not mistaken, this is because of VB.NET's lack of operator overloading; thus the need to call upon the .op_Implicit. I think there are usually other .op_XXX methods that assist in this manner for different objects as well. The same issue is encountered when attempting to check for equality on objects; some objects you have to use the .Equals instead of =.





    And to answer your question, yes, the behavior is the same in VS.NET 2003.


Comments have been disabled for this content.