Which Variable type is best to choosen for accepting Null Values?

Questions by vsateeshk   answers by vsateeshk

Showing Answers 1 - 15 of 15 Answers

Boogster

  • Jun 5th, 2007
 

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.

  Was this answer useful?  Yes

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...

  Was this answer useful?  Yes

mcapodici

  • Feb 9th, 2008
 

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.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions