C# Programming - Datatypes - Discussion
Discussion Forum : Datatypes - General Questions (Q.No. 11)
11.
Which of the following statements are correct?
- We can assign values of any type to variables of type object.
- When a variable of a value type is converted to object, it is said to be unboxed.
- When a variable of type object is converted to a value type, it is said to be boxed.
- Boolean variable cannot have a value of null.
- When a value type is boxed, an entirely new object must be allocated and constructed.
Discussion:
13 comments Page 1 of 2.
Rajesh said:
7 years ago
If bool? declare like that so it can be store null value by a null character. It means 1st and 5th are correct.
Omkar said:
7 years ago
Boolean is value type in C# hence must not be null.
Pankaj jindal said:
8 years ago
According to me, option 4 is also correct.
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.
4 is also correct. Boolean variable cannot have a null value.
3 is false because it is call unboxing.
Abhishek said:
1 decade ago
What is the problem with option 3 and 4? Please somebody explain me that.
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
http://msdn.microsoft.com/en-us/library/c8f5xwh7(v=vs.90).aspx
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.
Rajeev Varshney said:
1 decade ago
Example of Boxing and Unboxing are
int a;
object o=i;// boxing
int j=(int)o;// Unboxing
int a;
object o=i;// boxing
int j=(int)o;// Unboxing
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.
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.
Gopesh said:
1 decade ago
Boolean variable cannot have a value of null because it is a non-nullable value type.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers