{"id":25,"date":"2016-02-10T16:26:52","date_gmt":"2016-02-10T16:26:52","guid":{"rendered":"https:\/\/ibex.tech\/csharp\/?p=25"},"modified":"2026-06-17T09:26:31","modified_gmt":"2026-06-17T08:26:31","slug":"define","status":"publish","type":"post","link":"https:\/\/ibex.tech\/csharp\/c-sharp\/define\/define","title":{"rendered":"#define"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Source code based #define isn&#8217;t available in C# like in C++.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can&#8217;t use it to create macros. Bloody annoying, but get over it &#8211; you can&#8217;t!\u00a0 Instead, use constants.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">See <a href=\"https:\/\/ibex.tech\/csharp\/c_sharp\/memory\/constants\">constants here<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Example C# define usage<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>#if (!PLATFORM_IS_RPI &amp;&amp; !DEBUG)\n#endif\n\n#if THIS_IS_RPI_APP\n\n#elif THIS_IS_WIN32_INTERFACE_APP\n\n#else\n\n#endif<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">#if DEBUG<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">See <a href=\"https:\/\/ibex.tech\/csharp\/c_sharp\/application-control\/useful-things\">here<\/a>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">How #define is used in C#<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">#define is only used to create something to test against (e.g. #if DEBUG #endif)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">#define can only appear at the start of a file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">#define only has scope in the file it is defined in.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Global defines in C#<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">You can define for an entire project in Project Properties &gt;&nbsp;Build &gt; Conditional compilation symbols<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can then test those defines like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#if THIS_IS_RPI_APP\n\n#elif THIS_IS_WIN32_INTERFACE_APP\n\n#else\n\n#endif<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Source code based #define isn&#8217;t available in C# like in C++. You can&#8217;t use it to create macros. Bloody annoying, but get over it &#8211; you can&#8217;t!\u00a0 Instead, use constants. See constants here Example C# define usage #if DEBUG See here. How #define is used in C# #define is only used to create something to [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-25","post","type-post","status-publish","format-standard","hentry","category-define"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/25","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/comments?post=25"}],"version-history":[{"count":11,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/25\/revisions"}],"predecessor-version":[{"id":1233,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/25\/revisions\/1233"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/media?parent=25"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/categories?post=25"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/tags?post=25"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}