Jump to content

View more

Image of the Day

The beast has a mighty searchlight of evil! #screenshotsaturday https://t.co/bzKepOojDL
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

? operator

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 frazchaudhry   Members   

1220
Like
0Likes
Like

Posted 05 January 2014 - 11:04 AM

Hello,

        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?



#2 SiCrane   Moderators   

11783
Like
5Likes
Like

Posted 05 January 2014 - 11:07 AM

*
POPULAR

That's the notation for a nullable type.

#3 frazchaudhry   Members   

1220
Like
0Likes
Like

Posted 05 January 2014 - 11:19 AM

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.






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.