Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Using #define like in C++

Discussion in 'Scripting' started by Themp, Mar 5, 2013.

  1. Themp

    Themp

    Joined:
    Nov 8, 2011
    Posts:
    96
    I've tried using defines like I saw in other scripts on forums (they were C++) and they could redefine like everything like the definition of an int would be aiwufb

    so you could type

    aiwufb thisInt = 0;

    or even change void to whatever

    so

    public whatever Main()
    {

    }

    is this possible in C# too? I believe yes but Unity changes alot.. tried it myself quickly but getting Single-Line comment or end-of-line expected.
     
  2. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,614
    No, it's not possible in C#. The only thing you can do with #define statements in C# is use them to control #if blocks.
     
  3. Themp

    Themp

    Joined:
    Nov 8, 2011
    Posts:
    96
    aww too bad I really wanted to mess with my colleages head with the weirdest code ever..

    also why would u make such if statements and not use normal if statements?
     
  4. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,516
    Because #if statements are handled at compile time, which makes them useful for platform-specific code. For instance, some iOS code can't be run on desktop machines, and some code you write for desktop machines you probably wouldn't want to run on mobiles.

    As for messing with colleagues... yes, the kind of usage you're talking about does mess with people, and not just when it's done in jest. The things could easily become major headaches, so C#'s designers decided to restrict them to only the highest value, least painful parts of what they're used for.