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 do you mean by string objects are immutable?

0 Answers  


What will a loop recorder show?

0 Answers  


What is a verbatim string literal and why do we use it?

0 Answers  


What is the difference between array and arraylist in c#?

0 Answers  


What are events in C#?

0 Answers   CDC,






if i want to transmit binary data,,,will it be support by Webservices or any exceptions ? define

2 Answers  


What is dapper in c#?

0 Answers  


When you inherit a protected class-level variable, who is it available to?

5 Answers   CMC, IBM,


What?s the implicit name of the parameter that gets passed into the class? set method?

1 Answers  


Explain manifest in c#.

0 Answers  


Is c# different than c++?

0 Answers  


Can we declare class as protected?

0 Answers   Infosys,


Categories