Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 356581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:07:31+00:00 2026-05-12T12:07:31+00:00

When learning C# for the first time, I was astonished that they had no

  • 0

When learning C# for the first time, I was astonished that they had no support for macros in the same capacity that exists in C/C++. I realize that the #define keyword exists in C#, but it is greatly lacking compared to what I grew to love in C/C++. Does anyone know why real macros are missing from C#?

I apologize if this question is already asked in some form or another – I promise I spent a solid 5 minutes looking for duplicates before posting.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T12:07:31+00:00Added an answer on May 12, 2026 at 12:07 pm

    from the C# faq.

    http://blogs.msdn.com/CSharpFAQ/archive/2004/03/09/86979.aspx

    Why doesn’t C# support #define macros?
    In C++, I can define a macro such as:

    #define PRODUCT(x, y, z) x * y * z

    and then use it in code:

    int a = PRODUCT(3, 2, 1);

    C# doesn’t allow you to do this. Why?

    There are a few reasons why. The first is one of readability.

    One of our main design goals for C# is to keep the code very readable. Having the ability to write macros gives the programmer the ability to create their own language – one that doesn’t necessarily bear any relation to what the code underneath. To understand what the code does, the user must not only understand how the language works, but he must also understand all of the #define macros that are in effect at that point in time. That makes code much harder to read.

    In C#, you can use methods instead of macros, and in most cases, the JIT will inline them, giving you the same performance aspect.

    There’s also a somewhat more subtle issue. Macros are done textually, which means if I write:

    int y = PRODUCT (1 + 2, 3 + 4, 5 + 6)

    I would expect to get something that gives me 3 * 7 *11 = 231, but in fact, the expansion as I’ve defined it gives:

    int y = 1 + 2 * 3 + 4 * 5 + 6;

    which gives me 33. I can get around that by a judicious application of parenthesis, but its very easy to write a macro that works in some situations and not in others.

    Although C# doesn’t strictly speaking have a pre-processor, it does have conditional compilation symbols which can be used to affect compilation. These can be defined within code or with parameters to the compiler. The “pre-processing” directives in C# (named solely for consistency with C/C++, despite there being no separate pre-processing step) are (text taken from the ECMA specification):

    #define and #undef
    Used to define and undefine conditional compilation symbols

    #if, #elif, #else and #endif

    Used to conditionally skip sections of source code

    #line
    Used to control line numbers emitted for errors and warnings.

    #error and #warning
    Used to issue errors and warnings.

    #region and #endregion

    Used to explicitly mark sections of source code.

    See section 9.5 of the ECMA specification for more information on the above. Conditional compilation can also be achieved using the Conditional attribute on a method, so that calls to the method will only be compiled when the appropriate symbol is defined. See section 24.4.2 of the ECMA specifcation for more information on this.

    Author: Eric Gunnerson

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 257k
  • Answers 257k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I dont know what is the convention of your book,… May 13, 2026 at 10:41 am
  • Editorial Team
    Editorial Team added an answer Two things to look at here: Firstly, to get the… May 13, 2026 at 10:41 am
  • Editorial Team
    Editorial Team added an answer If you require various values to be stored together, in… May 13, 2026 at 10:41 am

Related Questions

When Joel Spolsky and Jeff Atwood began the disagreement in their podcast over whether
We have/had a phantom delay in our app. This was traced to the initialisation
I am currently using Q-Learning to try to teach a bot how to move
I have been a Half-Life lover for years. I have a BS in CS

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.