• Saves Valuable Time
  • Trusted Accuracy since 2004
  • 15-Day Money-Back Guarantee

C# Equivalent to VB Late Binding

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#.     

Additional resource: VB.NET and C# Equivalents

Copyright © 2004 – 2021 Tangible Software Solutions, Inc.