Câu hỏi phỏng vấn C#
Câu hỏi

What happens when we Box...

Câu trả lời

Here's an explanation of what happens when you box or unbox nullable types in C#:

Boxing Nullable Types

When you box a nullable type, the following happens:

  1. If the nullable type has a value (i.e., it's not null), the value is boxed into an object. This means a new object is created on the heap that contains the value of the nullable type.

  2. If the nullable type is null, boxing it results in a null reference.

Unboxing Nullable Types

When you unbox a nullable type, the following happens:

  1. If the boxed object contains a value that is compatible with the target nullable type, the value is unboxed into the nullable type.

  2. If the boxed object is null, unboxing it results in a null value for the nullable type.

  3. If the boxed object contains a value that is not compatible with the target nullable type, an In...

senior

senior

Gợi ý câu hỏi phỏng vấn

senior

What is the yield keyword used for in C#?

middle

What is sealed Class in C#?

junior

Why to use finally block in C#?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào