简体   繁体   中英

Access the same API from VB.NET or C#

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM