Thank you.
Why this is proper way? Is'nt it simpler to use
if(ob2 != null )
In this case HasValue property can be removed from Nullable<> struct
at all.
I will probably flub up the explanation a bit, but here goes.
There are two basic types in .NET base types. Value types (all of your
integral values, DateTime, structures you create, etc.) which are stored
as structures and placed on your application stack memory. There are
also reference types (any class you created, strings, etc), which are
stored on the heap.
When Microsoft first created .NET, the base types that were not
reference types had no concept of null. But there was a call for
nullable types, so MS had two choices:
1) Break all existing code by refactoring the value types to have a
null, so you could test like so
if(MyDateTime == null)
2) Create a generic wrapper class to create a nullable type without
altering the current structures, which requires the following test
if(!MyDateTime.HasValue)
Wisely, in my opinion, MS choose the later. Perhaps with more time to
get it done they could have figured a way of doing this without breaking
current code, but it works.
yes the !=null test would be more consistent, but breaking all of the
1.x code was a non-option, if you ask me.
Peace and Grace,
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
Twitter: @gbworld
Blog:
http://gregorybeamer.spaces.live.com
*******************************************
| Think outside the box! |
*******************************************