0

In regards to programming an application that interfaces with another application using an API, can I access the libraries (API) using VB as well as C# since effectively (from what I will call "limited understanding" at this point) both code compiles to effectively the same CIL or IL?

Edit: The application is built using C# already and the norm is writing C# for custom functionality using the application's API. I really don't know what type of API it is though.

2
  • 1
    Yes, but the library's interface should be "CLS Compliant" Commented Sep 14, 2013 at 7:37
  • 3
    Please clarify what kind of API it is - managed, native, COM, some remote web services/REST.... In general yes, but in some cases (i.e. dealing with IDispatch COM objects is somewhat easier in VB.Net) one may have more compact syntax. Commented Sep 14, 2013 at 7:41

1 Answer 1

2

In general, yes. Visual Basic had interop support long before C# came around so you tend to find declarations that use the Declare keyword. Which is not a completely substitute for pinvoke declarations. But that's not a problem, it supports the <DllImport> attribute just as well as C# does. And they both use the exact same pinvoke marshaller built into the CLR and expose all of its capabilities.

A small corner case are api declarations where you need to use pointers, not directly supported in VB.NET. Technically you can declare typed pointers in C# but you almost always flatten them to an IntPtr anyway. Which are just as usable in VB.NET as in C#.

Do commit to a language early, you don't want to spend the time doing it twice. And keep in mind that a wrapper class you'd write to hide the api complexity that's written in C# is usable from VB.NET as well. So it completely stops mattering if you do it right.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.