raghavendra v
raghavendra v

Reputation: 107

what is the below statement explains

public virtual int? NoRw { get; set; }

here what is then data type int? specifies with the property NoRw why we need to use like this

Upvotes: 3

Views: 61

Answers (3)

Binary Worrier
Binary Worrier

Reputation: 51711

int? is shorthand for Nullabe<int>.

Nullable<T> is a value type, and the generic type parameter must also be a value type.

A nullable type can contain a value, or no value at all e.g.

int? i; // same as Nullable<int> i;
Console.WriteLine("i.HasValue={0}", i.HasValue); // Writes i.HasValue=False
i = 10;
Console.WriteLine("i.HasValue={0}", i.HasValue); // Writes i.HasValue=True

You can use the ?? operator (i.e. the null-coalescing operator) with Nullable types.

int? i; // i has no value
// Now we want to add 10 to i, and put it in a, however
// a = i + 10 cannot work, because there is no value in i
// so what value should be used instead?
// We could do the following
int a = 10;
if(i.HasValue)
   a += (int)i;

// or we could use the ?? operator, 
int a = (i ?? 0) + 10; // ?? returns value of i, or 0 if I has no value

The ?? operator allows us to use nullable types and directly supply a meaningful alternative if there is no value.

Upvotes: 4

Pranay Rana
Pranay Rana

Reputation: 176906

public virtual int? NoRw { get; set; }

NoRw is virtual Nullable integer property

other example

Nullable<int> variable= null;
or
int? variable= null;

Check this post for more detail : Nullable type -- Why we need Nullable types in programming language ?

Upvotes: 2

Luke Girvin
Luke Girvin

Reputation: 13442

Nullable integer:

http://msdn.microsoft.com/en-us/library/1t3y8s4s(v=vs.80).aspx

A nullable type can represent the normal range of values for its underlying value type, plus an additional null value.

Upvotes: 4

Related Questions