C/C++ to c#


Am I right in saying that a C/C++ .h file can be compared to a Interface in C# and the .cpp file is the class in C# ?

Nope, not even slightly sorry.

An interface in C# is a contract between classes. There is no need for a .h file in C#. You could consider importing a header file similar to the ‘import’ statements at the top of a file that import in namespaces i guess.

See here: [url]Microsoft Learn: Build skills that open doors in your career for more info on interfaces.

In C and C++ the .H file is used to define structs, classes, constants, etc. and the .c or .cpp file contained the associated code. In c# these are combined in a single .cs file.

Also in .net when you reference an assembly in your project, the compile uses reflection to determine the namespaces and public items contained in the assembly and this is automatically available in your code if you add a “using” statement for the namespace.

You can look inside a referenced assembly to see what it contains by right-clicking on the reference and using the objectbrowser. This will let you see the contained namespaces etc.

Hope this helps


ok, i will give it a shot. I’m trying to convert some C/C++ libraries to C# classes ::slight_smile:

in that context, the .H file is more a “header” that allows you (and the compiler) to “see” the definition of what the “code” file (the associated .C file) allows a program to use in another location.

In VStudio “using” does a similar thing (negates the need to have fully qualified namespaces for objects).

A C# .cs file is like a C++ .h file with all methods defined inline.

A C# interface is like a C++ class definition containing only abstract methods.


Looks like there are a bunch of C/C++ fluent people here, give us a shout if you have any problems.



I will, but after I received the needed hardware. It’s hard to write a driver without the hardware.