top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

How to use nullable types in .Net?

+4 votes
42 views
How to use nullable types in .Net?
posted Nov 28, 2014 by Manikandan J

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

Value types can take either their normal values or a null value. Such types are called nullable types.

[csharp]Int? someID = null;
If(someID.HasVAlue)
{
}
[/csharp]
answer Dec 1, 2014 by Shivaranjini
0 votes

Nullable types allow you to create a value type variable that can be marked as valid or invalid so that you can make sure a variable is valid before using it. Regular value types are called non-nullable types.

The important things you need to know about nullable type conversions are the following:

• There is an implicit conversion between a non-nullable type and its nullable version. That is, no cast is needed.
• There is an explicit conversion between a nullable type and its non-nullable version.

For example, the following lines show conversion in both directions. In the first line, a literal of type
int is implicitly converted to a value of type int? and is used to initialize the variable of the nullable type.
In the second line, the variable is explicitly converted to its non-nullable version.

int? myInt1 = 15; // Implicitly convert int to int?
int regInt = (int) myInt1; // Explicitly convert int? to int

int? myInt1 = 15; // Implicitly convert int to int?
int regInt = (int) myInt1; // Explicitly convert int? to int

answer May 9, 2017 by Jdk
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...