int
and
bool
type:
int? count;
bool? done;
When using nullable types, you will often see a nullable object created like this:
int? count = null;
This explicitly initializes
count
to
null
. This satisfies the constraint that a variable must be
given a value before it is used. In this case, the value simply means undefined.
You can assign a value to a nullable variable in the normal way because a conversion
from the underlying type to the nullable type is predefined. For example, this assigns the
value 100 to
count
.
count = 100;
There are two ways to determine if a variable of a nullable type is
null
or contains a
value. First, you can test its value against
Do'stlaringiz bilan baham: |