|
-
January 30th, 2013, 02:47 PM
#4
Re: Convert this line from C++ to C#
 Originally Posted by RyuMaster
Wonder why use #define in the first place at all
#define is a pre-processor directive. It makes sense to use in C++ because it's code shorthand. Macro use is popular in C++, such as the MFC/ATL TRACE macro.
The drawback to them in C++ is that you can't step into them while debugging.
In C#, you can do something similar using a static method. You can't do everything with a static method, because static methods aren't pre-processor directives; however, this is both good and bad because preprocessor directives aren't type safe, but sometimes you need a macro that takes advantage of the preprocessor and a static method won't do.
On the bright side, in the 10 years I've spent programming in C#, I have yet to run into a situation where I couldn't convert a C++ macro into an equivalent C# method. Sometimes, I needed to refactor the code a bit, but was always able to get it done. In some cases, it might be better to understand the C++ code and rewrite it in a C# way.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|