C# Programming - Datatypes - Discussion

Discussion Forum : Datatypes - General Questions (Q.No. 11)
11.
Which of the following statements are correct?
  1. We can assign values of any type to variables of type object.
  2. When a variable of a value type is converted to object, it is said to be unboxed.
  3. When a variable of type object is converted to a value type, it is said to be boxed.
  4. Boolean variable cannot have a value of null.
  5. When a value type is boxed, an entirely new object must be allocated and constructed.
2, 5
1, 5
3, 4
2, 3
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
13 comments Page 1 of 2.

Rahul said:   1 decade ago
Boolean variable cannot have a value of null - is a correct one.

Girish Menghani said:   1 decade ago
We can create a Boolean variable which have null value by assigning it "-1" that represents "null Boolean value".

Morsi said:   1 decade ago
Boolean test = -1;

Constant value '-1' cannot be converted to a 'bool'

Gopesh said:   1 decade ago
Boolean variable cannot have a value of null because it is a non-nullable value type.

Rajeev Varshney said:   1 decade ago
Answer is 1 & 5.

1) We can assign the any type value to the variable of object data type.

5) Boxing means suppose you have declared a variable as simple data type and we can change it into reference type.

After task complete if we want to change the reference type into simple data type it is called unboxing.

Rajeev Varshney said:   1 decade ago
Example of Boxing and Unboxing are
int a;
object o=i;// boxing
int j=(int)o;// Unboxing

EliasHdez said:   1 decade ago
The nullable Boolean type bool? can represent three values, true, false, and null, and is conceptually similar to the three-valued type used for Boolean expressions in SQL.

Ibrahim said:   1 decade ago
If you require a Boolean variable that can also have a value of null, use bool?. For more information, see Nullable Types (C# Programming Guide).

http://msdn.microsoft.com/en-us/library/c8f5xwh7(v=vs.90).aspx

Abhishek said:   1 decade ago
What is the problem with option 3 and 4? Please somebody explain me that.

Baz said:   9 years ago
@Abhishek.

4 is also correct. Boolean variable cannot have a null value.
3 is false because it is call unboxing.


Post your comments here:

Your comments will be displayed after verification.