Is there an equivalent for the C# 4 'dynamic' keyword when using 'type safe VB.Net', i.e. with Option Strict On?
The equivalent is Object in VB.NET but with Option Strict Off
. With Option Strict On
there's no equivalent. Put another way the dynamic keyword brings Option Strict Off
equivalent functionality to C#.
You can turn Option Infer On and Option Strict Off and still have something very close.
Hmya, VB.NET always had the "dynamic" feature built in. This syntax was supported forever:
Dim obj = new SomeComClass()
obj.DoSomething()
The dynamic keyword was C#'s way of catching up to what VB.NET could do for a long time. Nevertheless, VB.NET version 10 did gain some additional capabilities, it is using the DLR as well. Which allows you to interop with IronPython and IronRuby. C# copied many other VB.NET features. Like optional parameters and support for properties that take arguments.
The syntax is exactly the same, use the Dim keyword without As. You will however have to use Option Strict Off, Option Infer On can soften that blow a bit. It does show that C# adding the dynamic keyword was a pretty good move.