C++ class defined in header file. Implementation in C# ?
-
I'm trying to port some old C++ code to C#. I have a few classes that were defined in a ".h" file. Their constructors and member variables were defined in the corresponding .cpp file. What is the best way to port this file to C#. More specifically: 1. I assume that the class, its constructor and methods are all defined together as follows: class DSP { // constructor // methods } Is this correct? 2. The original C++ listing in the .h file is as follows: class DSP { public: // public variables protected: //constructor // destructor // private variables void SomeMethod() }; These public variables need to be properties that can be assigned to. Therefore in the C# implementation, do I need to define these fields with "get" and "set" properties? I know these are very elementary questions, but I haven't ported any C++ code over to C# before, and I appreciate your help!
-
I'm trying to port some old C++ code to C#. I have a few classes that were defined in a ".h" file. Their constructors and member variables were defined in the corresponding .cpp file. What is the best way to port this file to C#. More specifically: 1. I assume that the class, its constructor and methods are all defined together as follows: class DSP { // constructor // methods } Is this correct? 2. The original C++ listing in the .h file is as follows: class DSP { public: // public variables protected: //constructor // destructor // private variables void SomeMethod() }; These public variables need to be properties that can be assigned to. Therefore in the C# implementation, do I need to define these fields with "get" and "set" properties? I know these are very elementary questions, but I haven't ported any C++ code over to C# before, and I appreciate your help!
C# classes do not have header files, pretty much anything in the header can be discarded. The declaration of functions in C# is the same as the definition, and everything can automatically see the namespaces in the project, without having to include anything. Yes, the best way to set properties is with get/set methods, then you can make variables that can be got and not set, and vice versa, if needed. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder