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

middle

What is Virtual Method in C#?

expert

What is deep or shallow copy concept in C#?

junior

What is enum in C#?

Bình luận

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

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