What is Nullable Type in c#

Answers were Sorted based on User's Feedback



What is Nullable Type in c#..

Answer / raju

Nullable type is nothing but value type cant store null values
only reference type can store null values.whenever you
assign null values to value type variable from your backend
tables at that time we use nullable.

int? x;

Is This Answer Correct ?    26 Yes 2 No

What is Nullable Type in c#..

Answer / mistry

Nullable types are instances of the System.Nullable struct.
A nullable type can represent the normal range of values
for its underlying value type, plus an additional null
value. For example, a Nullable<Int32>, pronounced "Nullable
of Int32," can be assigned any value from -2147483648 to
2147483647, or it can be assigned the null value. A
Nullable<bool> can be assigned the values true or false, or
null. The ability to assign null to numeric and Boolean
types is particularly useful when dealing with databases
and other data types containing elements that may not be
assigned a value.

Is This Answer Correct ?    6 Yes 0 No

What is Nullable Type in c#..

Answer / sagar

csharp provided a new concept of nullable type in which we
can store null values to integer data type , previously
like c , c++ its not possible to store null values in value
types,this languages supports to store null values only in
reference types.

Is This Answer Correct ?    4 Yes 1 No

What is Nullable Type in c#..

Answer / vishnu

Declare a variable as nullable if you want to be able to
determine whether a value has been assigned. For example, if
you are storing data from a yes/no question on a form and
the use did not answer the question, you should store a null
value. The following code declares a boolean variable the
can be true, false, or null:

`VB
Dim b As Nullable(of Boolean) = Nothing

//C#
Nullable<bool> b = null;

//Shorthand notation, only for C#
bool? b = null;

Declaring a variable as nullable enables the HasValue and
Value members. Use HasValue to detect whether a value has
been set as follows:

`VB
If b.HasValue Then Console.WriteLine(“b is {0}.”, b.Value)
Else Console.WriteLine(“b is not set”);

//C#
If (b.HasValue)
Console.WriteLine(“b is {0}.”, b.Value);
Else
Console.WriteLine(“b is not set.”);

----------------------------

Exmaple:
class NullableExample
{
static void Main()
{
int? num = null;
if (num.HasValue == true)
{
System.Console.WriteLine("num = " + num.Value);
}
else
{
System.Console.WriteLine("num = Null");
}

//y is set to zero
int y = num.GetValueOrDefault();

// num.Value throws an InvalidOperationException if
num.HasValue is false
try
{
y = num.Value;
}
catch (System.InvalidOperationException e)
{
System.Console.WriteLine(e.Message);
}
}
}

Is This Answer Correct ?    1 Yes 1 No

What is Nullable Type in c#..

Answer / master

which is nullable... is the nullable type....

Is This Answer Correct ?    2 Yes 21 No

Post New Answer

More C Sharp Interview Questions

What is dependency injection in simple words?

0 Answers  


How do I download a program to my desktop?

0 Answers  


what is c# command?

0 Answers  


explain the three services model commonly know as a three-tier application.

0 Answers   Siebel Systems,


Why we can't create the object of abstract class ?

15 Answers   Assyst, CTS, HCL, IBM, L&T,






How main method is called in c#?

0 Answers  


What is difference between dll and exe in c#?

0 Answers  


What is a console application in c#?

0 Answers  


What is binary search tree in data structure?

0 Answers  


Can we inherit static class in c#?

0 Answers  


What is dll in vb.net?

0 Answers  


What is a nested type. Give an example?

0 Answers  


Categories