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

Explain when to use F...

Câu trả lời

Here is a concise answer to the interview question "Explain when to use Finalize vs Dispose in C#":

Use the Dispose method when you need to explicitly free unmanaged resources held by an object, such as file handles, database connections, or native resources[1][2][3]. Dispose should be called by the consumer of the object when they are done using it[1][4]. Implementing Dispose allows you to take advantage of the using statement to ensure Dispose is always called[4].

Use the Finalize (destructor) method as a last resort to free unmanaged resources if Dispose was not called[1][2][3]. The garbage collector will call Finalize when the object is about to be collected, but this is non-deterministic and Finalize is slower than Dispose[2][3][5].

It is recommended to implement both Dispose and Finalize together us...

expert

expert

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

junior

What you understand by Value types and Reference types in .NET? Provide some comparison

middle

Why can't you specify the accessibility modifier for methods inside the Interface?

senior

IEnumerable vs List - What to Use? How do they work?

Bình luận

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

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