本文介紹了C#:應該將對象變量分配給 null 嗎?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
在 C# 中,如果您已經使用完一個對象變量,是否有必要將其分配給 null
,即使它無論如何都會超出范圍?
In C#, is it necessary to assign an object variable to null
if you have finished using it, even when it will go out of scope anyway?
推薦答案
不,這實際上可能很危險且容易出錯(考慮一下有人可能會在以后嘗試使用它,而沒有意識到它已被設置)為空).僅當存在將其設置為 null 的合乎邏輯的原因時才將其設置為 null.
No, and that could in fact be dangerous and bug-prone (consider the possibility that someone might try to use it later on, not realizing it had been set to null). Only set something to null if there's a logical reason to set it to null.
這篇關于C#:應該將對象變量分配給 null 嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!