Jump to content
  • Advertisement
Sign in to follow this  

? operator

This topic is 2117 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


        I am trying to understand the the XNA gamestate sample. Everything looks good except for one strange C# syntax that I have not seen before. It has to do with the ? operator. I am familiar with the conditional ? operator which can be used like this

(condition) ? statement if true : statement if false;

The code in the sample is

public PlayerIndex? ControllingPlayer
            get { return controllingPlayer; }
            internal set { controllingPlayer = value; }

        PlayerIndex? controllingPlayer;

where the PlayerIndex is an enum. The rest of the code also uses the PlayerIndex with a "?" at the end. What does the "?" operator do in this case?

Share this post

Link to post
Share on other sites

Thanks. In the code they do assign a null value to this variable, and I was wondering how they did that since the values allowed by the PlayerIndex are One, Two, Three, and Four. The link that you provided was very useful, much appreciated.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!