GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Microsoft  >  C#
Go To First  |  Previous Question  |  Next Question 
 C#  |  Question 387 of 436    Print  
Which Variable type is best to choosen for accepting Null Values?

  
Total Answers and Comments: 5 Last Update: February 09, 2008     Asked by: vsateeshk 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
June 05, 2007 00:10:30   #1  
Boogster        

RE: Which Variable type is best to choosen for accepti...
IMAO String value is the best type for accepting null values Correct me if I'm wrong I think it is the only value type accepting null values.
 
Is this answer useful? Yes | No
June 14, 2007 07:54:42   #2  
avkdsiva Member Since: June 2006   Contribution: 9    

RE: Which Variable type is best to choosen for accepti...
Nullable types are introduced in .NET 2.0 which may be handy
 
Is this answer useful? Yes | No
November 19, 2007 16:20:16   #3  
unfed_neuron Member Since: November 2007   Contribution: 1    

RE: Which Variable type is best to choosen for accepti...
Nullable types are meant only to be used for ADO.net. That means if you are expecting an integer (like zip code) from a query and query returns no rows the data type used must be nullable type...

Nullable data type means which accpets NULL values apart from accpeting permitted values.. for eg. a bool datatype will take yes no and also NULL if its declared as nullable...

 
Is this answer useful? Yes | No
February 03, 2008 09:12:43   #4  
sarnam Member Since: February 2007   Contribution: 14    

RE: Which Variable type is best to choosen for accepting Null Values?
string variable is assigned a null value by default.
 
Is this answer useful? Yes | No
February 09, 2008 06:46:14   #5  
mcapodici Member Since: February 2008   Contribution: 1    

RE: Which Variable type is best to choosen for accepting Null Values?
In .NET 1.1 you can use the type "object" to store the values. You then have the choice of setting the object reference to "null" or storing the value. The issue here is that the object could contain any type of information and you would need to cast. An Exception may result if the wrong type of object has been stored. If you are in control of the object at all times this shouldn't be a problem. But it may cause issues if you interface the object into code written by other people or companies where you have no control over what is done to your object.

Another option is to create your own Nullable type. E.g. NullableInt with methods to get/set the integer value and methods to determine if the value is null.

In .NET 2.0 you can use the Nullable Types feature to quickly make a nullable type of any type you desire. This will provide get / set methods and properties to determine if the value is null.

So whats the best? I'd say .NET 2.0 Nullable Types.

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape