Monday, January 23, 2012

Working with Nullable Types

******************* Type 1 ***********************
int iUnits;
int iStock ;
if (iStock== null)
  {
      iUnits= 0;
   }
else
 {
     iUnits= (int)iStock;
}

******************* Type 2 ***********************
// using the coalesce operator, ??,
    int iUnits= iStock ?? 0; 
The coalesce operator works like this: if the first value (left hand side) is null, then C# evaluates the second expression (right hand side).

No comments:

Post a Comment

Hash Table in C#

 The Hashtable is a non-generic collection and used to store the key/value pairs based on the hash code of the key. Key will be used to acce...