3 Replies - 188 Views - Last Post: 25 July 2012 - 11:29 AM Rate Topic: -----

#1 UofMCreed  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 04-October 08

Help understanding a syntax issue

Posted 25 July 2012 - 11:08 AM

Hello,

I'm sry if this is a repost of something I didn't see but I am having a little trouble understanding what a part of a line of code does:

 public DateTime? LastNudged { get; set; }



I understand that it is a property I'm just unclear to what the "?" does, if anything. I'll keep trying to find an answer but if anyone can give me a simple explaination or a point me in the right direction I would greatly appreciate it.

Thanks for your time.

Is This A Good Question/Topic? 0
  • +

Replies To: Help understanding a syntax issue

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 6434
  • View blog
  • Posts: 23,423
  • Joined: 12-June 08

Re: Help understanding a syntax issue

Posted 25 July 2012 - 11:12 AM

The ? after a datatype makes it nullable.. That means, in your example, LastNudged can be a datetime or null.

http://msdn.microsof...v=vs.80%29.aspx
Was This Post Helpful? 2
  • +
  • -

#3 Curtis Rutland  Icon User is online

  • (╯°□°)╯︵ (~ .o.)~
  • member icon


Reputation: 3792
  • View blog
  • Posts: 6,387
  • Joined: 08-June 10

Re: Help understanding a syntax issue

Posted 25 July 2012 - 11:15 AM

The ? after a type name changes that type to a nullable type. In fact, it's a shortcut syntax for System.Nullable<T>.

http://msdn.microsof...(v=vs.110).aspx

Using your example:

public DateTime? LastNudged {get;set;}
//is the same as this:
public Nullable<DateTime> LastNudged {get;set;}


It's just a simpler syntax.

What that means is that it allows types that aren't naturally able to accept null to accept it. It's really just a wrapper class.
Was This Post Helpful? 2
  • +
  • -

#4 UofMCreed  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 04-October 08

Re: Help understanding a syntax issue

Posted 25 July 2012 - 11:29 AM

Thanks for the help!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1