改善我的写作 - 2005年 [英] improving my writing - 2005

查看:69
本文介绍了改善我的写作 - 2005年的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我作为注册表类的一部分

公共函数DoesKeyExist()As Boolean


Dim oReg作为RegistryKey


Dim bExist As Boolean = False


尝试


oReg = m_MSRegRoot.OpenSubKey(m_sKeyPath,False)


如果不是oReg什么都没有那么


bExist = True


结束如果


Catch ex As Exception


''


最后


如果不是什么都不是


oReg.Close()


oReg =没什么


结束如果


结束尝试


返回bExist


结束功能

>
2005 IDE警告''变量oReg在被赋值之前使用。

空引用异常可能在运行时产生''


我的问题是 - 我该怎么做呢?

解决方案

Terry,

dim oReg as RegistryKey = Nothing




我强烈反对你。你用它做的唯一一件事是

创建额外的代码并禁用对错误使用的代码的检查。


Cor


当你声明变量时,给它分配一个初始值......例如:


dim oReg as RegistryKey = Nothing


***通过开发人员指南 http://www.developersdex.com 发送* **


: - 0

OMG。我在大多数其他地方使用它。


为什么我的大脑没有收到错误消息?

谢谢Terry

Terry Olsen <到****** @ hotmail.com>在消息中写道

news:%2 ****************** @ TK2MSFTNGP12.phx.gbl ...

当你声明变量时,给它分配一个初始值......例如:

dim oReg as RegistryKey = Nothing

***通过Developersdex发送 http://www.developersdex.com ***



below is what I have as part of registry class
Public Function DoesKeyExist() As Boolean

Dim oReg As RegistryKey

Dim bExist As Boolean = False

Try

oReg = m_MSRegRoot.OpenSubKey(m_sKeyPath, False)

If Not oReg Is Nothing Then

bExist = True

End If

Catch ex As Exception

''

Finally

If Not oReg Is Nothing Then

oReg.Close()

oReg = Nothing

End If

End Try

Return bExist

End Function

2005 IDE warns ''Variable oReg is used before it has been assigned a value.
A null reference exception could result at runtime''

My question is - how am I supposed to do this?


解决方案

Terry,

dim oReg as RegistryKey = Nothing



I strongly disagree with you. The only thing what you do with this is
creating extra code and disable the checking on wrong used code.

Cor


When you declare the variable, assign it an initial value...such as:

dim oReg as RegistryKey = Nothing

*** Sent via Developersdex http://www.developersdex.com ***


:-0

OMG. I use that in most other places.

Why did my brain not associate that with the error message recieved?
Thanks Terry
"Terry Olsen" <to******@hotmail.com> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...

When you declare the variable, assign it an initial value...such as:

dim oReg as RegistryKey = Nothing

*** Sent via Developersdex http://www.developersdex.com ***



这篇关于改善我的写作 - 2005年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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