C#:应该对象变量被分配到空? [英] C#: should object variables be assigned to null?

查看:156
本文介绍了C#:应该对象变量被分配到空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,就是如果你使用完它需要分配一个对象变量,即使它会走出去的范围呢?

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#:应该对象变量被分配到空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆