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:

csharp Copy
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

middle

When to use Record vs Class vs Struct in C#?

middle

What are the uses of using in C#

expert

What is a preprocessor directives in C#?

Bình luận

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

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