Thread: Point

  1. #1
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853

    Point

    Why can't you do Point p = null? It says it is non-nullable, but why?

  2. #2
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    That's something you should really be asking Anders and his cohorts.
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

  3. #3
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    Point is a value type. It is a structure. Probably the most popular example in books when they are talking about the differences between reference and value types in c# :P

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Use:
    Code:
    System.Drawing.Point? Point = null;
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Yeah, haven't read any books for C#. Don't generally have a problem but I miss some small details.

    So, what does the ? exactly do here? I guess it makes Point nullable, eh?

  6. #6
    Registered User
    Join Date
    Aug 2008
    Posts
    188
    yeah, it allows valuetypes to have a 'null' state, which is particularly useful for databases. it adds 2 properties to the instance, for example:
    Code:
    if (blah.IsValid) {
      // blah.Value
    }

  7. #7
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Quote Originally Posted by bling View Post
    yeah, it allows valuetypes to have a 'null' state, which is particularly useful for databases. it adds 2 properties to the instance, for example:
    Code:
    if (blah.IsValid) {
      // blah.Value
    }
    It's "blah.HasValue"
    And "?" is syntactic sugar for "System.Nullable<>"
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  8. #8
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Magos View Post
    And "?" is syntactic sugar for "System.Nullable<>"
    I think I just threw up a little in my mouth.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  9. #9
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Why? It's much more convenient to write
    Code:
    int? X = null;
    than
    Code:
    System.Nullable<int> X = null;
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  10. #10
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Magos View Post
    Why? It's much more convenient to write
    Code:
    int? X = null;
    than
    Code:
    System.Nullable<int> X = null;
    A lot of things would be convenient if the compiler had special cases for them... Where do you stop?

    I'm no C# expert, but the little I've used it I've liked it. This bit of "syntactic sugar" just seems like Microsoft slapping itself on the back for being so clever...
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  11. #11
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    Well, you're not forced to use it, and there are quite a bit of those "accomplishments" in the C# language that are optional. The entire linq set is optional syntactic sugar but I love it more than using extension methods and lambdas

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help realy needed
    By ZohebN in forum C++ Programming
    Replies: 2
    Last Post: 04-08-2008, 09:37 AM
  2. Getting a floating point exception
    By SnertyStan in forum C Programming
    Replies: 13
    Last Post: 03-25-2008, 11:00 AM
  3. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 02:39 PM
  4. floating point binary program, need help
    By ph34r me in forum C Programming
    Replies: 4
    Last Post: 11-10-2004, 07:10 AM
  5. point lies in circle?
    By cozman in forum Game Programming
    Replies: 3
    Last Post: 12-20-2001, 04:39 PM