VB uses the 'CreateObject' function to acquire a type instance at run-time where the type is unknown at compile time. VB then allows invoking members of this instance even though the type is unknown at compile time (this requires the VB Option Strict setting to be turned off). C# allows the same behavior via the 'dynamic' keyword and a call to System.Activator.CreateInstance:
|Dim o As Object = CreateObject(progID)
o.Foo() 'late-bound call to 'Foo' method
|dynamic o = System.Activator.CreateInstance(System.Type.GetTypeFromProgID(progID));
o.Foo(); //late-bound call to 'Foo' method
Use Instant C# to convert from VB.NET to C#.
VB.NET and C# Equivalents
Copyright © 1997 – 2019 Tangible Software Solutions, Inc.