65873 members! Sign up to stay informed.

Sponsored Links


Resources

.NET Research Library
Get .NET related white papers, case studies and webcasts

News News News Messages: 9 Messages: 9 Messages: 9 Printer friendly Printer friendly Printer friendly Post reply Post reply Post reply XML XML XML

Microsoft Adds New Support for Nullable Types in .NET 2.0

Posted by: Thibaut Barrere on August 23, 2005 DIGG
Microsoft has added a last minute change to the implementation of Nullable types in .NET 2.0. This change allows for simpler null checks when using boxed references and generics. This new feature also provides the ability to coerce a nullable type to an interface implemented by the enclosed type.
The outcome is that the Nullable type is now a new basic runtime intrinsic. It is still declared as a generic value-type, yet the runtime treats it special. One of the foremost changes is that boxing now honors the null state. A Nullabe int now boxes to become not a boxed Nullable int but a boxed int (or a null reference as the null state may indicate.) Likewise, it is now possible to unbox any kind of boxed value-type into its Nullable type equivalent.

Read more at Somasegar's Weblog

Threaded replies

·  Microsoft Adds New Support for Nullable Types in .NET 2.0 by Thibaut Barrere on Tue Aug 23 07:52:15 EDT 2005
  ·  big fat mistake by peter lin on Tue Aug 23 11:33:57 EDT 2005
    ·  Is there a difference? by Mike Griffin on Tue Aug 23 13:52:14 EDT 2005
      ·  int? by Kevin Lewis on Tue Aug 23 18:59:14 EDT 2005
        ·  int? by Mike Griffin on Wed Aug 24 00:16:16 EDT 2005
          ·  It's only in the Runtime... by Cornelius van Berkel on Wed Aug 24 04:45:14 EDT 2005
            ·  It's only in the Runtime... by Mike Griffin on Wed Aug 24 09:56:12 EDT 2005
            ·  It's only in the Runtime... by peter lin on Wed Aug 24 12:21:01 EDT 2005
              ·  Very good news by Ruslan Zenin on Fri Aug 26 12:24:31 EDT 2005
  ·  Microsoft Adds New Support for Nullable Types in .NET 2.0 by Star Trooper on Thu Aug 25 08:46:48 EDT 2005
  Message #182205 Post reply Post reply Post reply Go to top Go to top Go to top

big fat mistake

Posted by: peter lin on August 23, 2005 in response to Message #182172
I can't help but feel this feature is ripe for abuse and unmaintainable code. When some other programmer has to fix or patch the code, how long is it going to take to figure out what it means. I really wish Microsoft would push for better coding and development practices and less on questionable features. Having spent lots of time fixing really aweful code, I can see the rampant abuse now.

I'm sure plenty of people will disagree.

peter

  Message #182224 Post reply Post reply Post reply Go to top Go to top Go to top

Is there a difference?

Posted by: Mike Griffin on August 23, 2005 in response to Message #182205
I've looked at the syntax in the blog post but I am failing to see any change at all in the syntax, either that or I need to go back and re-read it. Was the change just in the hidden boxing/unboxing stuff?

  Message #182244 Post reply Post reply Post reply Go to top Go to top Go to top

int?

Posted by: Kevin Lewis on August 23, 2005 in response to Message #182224
Instead of "int" you have "int?".

  Message #182249 Post reply Post reply Post reply Go to top Go to top Go to top

int?

Posted by: Mike Griffin on August 24, 2005 in response to Message #182244
Ya, but that was always the case, for like a year now?

  Message #182259 Post reply Post reply Post reply Go to top Go to top Go to top

It's only in the Runtime...

Posted by: Cornelius van Berkel on August 24, 2005 in response to Message #182249
<Quote>
Once an instance of the type was boxed (by casting to the base ‘Object’ type), it became a boxed value type, and no matter what its original ‘null’ state claimed, the boxed value-type was never null.
</Quote>

They tweaked the runtime behaviour of the generic Nullable struct, so that when the HasValue field is false and you assign it to a variable ot type object, this variable will be null, which is good, instead of being a boxed instance of that nullable type which is null...

Therefore I think this change is very nice and intuitive.
Big up for the guys fixing this...

  Message #182301 Post reply Post reply Post reply Go to top Go to top Go to top

It's only in the Runtime...

Posted by: Mike Griffin on August 24, 2005 in response to Message #182259
I agree, big up, didn't know the issue existed however. Anyway, it works now how it should ...

  Message #182328 Post reply Post reply Post reply Go to top Go to top Go to top

It's only in the Runtime...

Posted by: peter lin on August 24, 2005 in response to Message #182259
<Quote>Once an instance of the type was boxed (by casting to the base ‘Object’ type), it became a boxed value type, and no matter what its original ‘null’ state claimed, the boxed value-type was never null.</Quote>They tweaked the runtime behaviour of the generic Nullable struct, so that when the HasValue field is false and you assign it to a variable ot type object, this variable will be null, which is good, instead of being a boxed instance of that nullable type which is null...Therefore I think this change is very nice and intuitive.Big up for the guys fixing this...

ok.. that makes much more sense. I retract my statement about it being a big mistake. though the blog and article both did a horrible job explaining it. not that I haven't horrible articles myself, but it would be better to have a clearer explanation.

peter

  Message #182426 Post reply Post reply Post reply Go to top Go to top Go to top

Microsoft Adds New Support for Nullable Types in .NET 2.0

Posted by: Star Trooper on August 25, 2005 in response to Message #182172
Why is the fuss with this very basic feature? Man, I can hardly believe the happiness and ectasis people is now feeling about being able to have a "Nullable Object"

As for myself... I'll stick to using the NullableObjects framework from SourceForge. It has solved my problems for more than 1.5 years by now.

Good luck!

  Message #182622 Post reply Post reply Post reply Go to top Go to top Go to top

Very good news

Posted by: Ruslan Zenin on August 26, 2005 in response to Message #182328
We have had discussed this ability for primitive types on Java thread here:
http://www.theserverside.com/discussions/thread.tss?thread_id=30463

I wish such feature would be included into next release of Java...

 
New content on TheServerSide.NETNew content on TheServerSide.NETNew content on TheServerSide.NET

DSLs and language interop

Language "mashups" will become more prominent, and developers will become polyglots, one programmer suggests.

VS 2008 Resources

SearchWinDevelopment.com offers an introduction to the language, performance, testing and data management improvements in VS 2008.

VB code downloads home

VBCode.com code snippets cover all aspects of application development, from data binding to security to the user interface.

XAML Learning Guide

Get up to date on XAML best practices with a variety of articles, tutorials and webcasts. [SearchWinDevelopment.com]

Company uses VSTS DB edition to tame workflow

One team's experience with the VSTS DB edition suggests that it can improve workflow for dev teams. It also enhanced Agile efforts. (June 24, Article)

Book: Intro to DSL Tools

Microsoft has begun to include DSL tools in the VSTS kit. A new book by Steve Cook and other VSTS team members helps set the stage. (June 24, Article)

I See the Silverlight Shining!

Cartoon: Be it ever so humble there is no place like your home after you get a Microsoft Home Server . (June 18, Cartoon)

A look at .NET 3.5

Microsoft's Thom Robbins says new technology to highlight in NET 3.5 includes AJAX, LINQ for both C# and VB, as well as tooling enhancements intended to ease the task of building WPF, WF and WCF apps. (June 29, Podcast)

Venkat Subramaniam on AJAX

Venkat Subramaniam discusses AJAX bottlenecks, the tenets of Agile development and more. He spoke at the Ajax Experience. (June 25, Tech Talk)

Building a Claims-Based Security Model in WCF - Part 2

In the second of a two-part series, Michele Leroux Bustamente discusses design decisions related to the claims-based security model. Read the story and walk through the process for creating a set of claims-based utilities to encapsulate claims authorization at the service tier. (May 24, Article)

Introducing the Entity Framework

Understanding why the Entity Framework exists and learning where it can fit into your projects can get you prepared for the eventual release early next year. (May 10, Article)

WCF Security Learning Guide

Resource: This learning guide gives you quick access to useful links on Windows Communication Foundation security information. (April 24, Article)

Brad Abrams: Patterns for successful ASP.NET AJAX development

TSS.NET's Jack Vaughan spoke recently spoke with Microsoft's Brad Abrams to find out what he is seeing in the field and what the chefs in Redmond are cooking. Along the way he discusses patterns of AJAX frameworks. (April 11, Article)

Building a Claims-Based Security Model in WCF

In a two-part series, Michele Leroux Bustamente explains how claims-based security is supported by WCF, and how you can implement a claims-based security model for your services. (March 29, Article)

Authoring workflow using XAML

Windows Workflow Foundation is a new technology that many developers will need to get their heads around. In a brief excerpt adapted from Programming Windows Workflow Foundation: Practical WF Techniques and Examples using XAML and C#, K.Scott Allen considers aspects of workflow definition. (March 22, Chapter Excerpt)

News | Blogs | Discussions | Tech talks | Patterns | Reviews | White Papers | Downloads | Articles | Media kit | About
All Content Copyright ©2007 TheServerSide Privacy Policy
Site Map