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

What is Boxing and Unboxing?

Câu trả lời

Boxing and Unboxing in C#

Boxing and unboxing are two related concepts in C# that allow the conversion between value types and reference types. Here's an explanation of each:

Boxing

Boxing is the process of converting a value type to a reference type. When a value type is boxed, it is converted to an object type and stored on the managed heap. This allows the value type to be treated as an object, which means it can be passed as a parameter to methods that expect an object, stored in collections that store objects, or used with other reference types.

Here's an example of boxing:

int i = 42;
object obj = i;

In this example, the integer value 42 is boxed into an object reference. The actual integer value is copied into a new object on the managed heap.

Unboxing

Unboxing is the reverse process of boxing. It involves converting a reference type back to a value type. To u...

junior

junior

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

senior

Explain the difference between Select and Where

senior

What happens when we Box or Unbox Nullable types?

expert

What's the difference between the System.Array.CopyTo() and System.Array.Clone() ?

Bình luận

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

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