有什么不同? [英] Whats the difference?

查看:81
本文介绍了有什么不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这只是一条警告信息,但我想知道为什么IDE标记

带有警告的第一个函数,而不是第二个函数。警告

消息是:

函数''GetView''在所有代码路径上都没有返回值。使用结果时,可能会在运行时发生null

引用异常。

以下是代码:

__________________________________________________ ____________________

Public Class SearchMgr

Public Enum SearchMgrTables

订阅

联系人

发票

结束枚举

..

..

..

公共函数GetView(ByVal表As SearchMgrTables,ByVal colname As

String)As DataView

Select Case table

Case SearchMgrTables.Subscriptions

如果SubSrchMgr什么都没有呢

SubSrchMgr =新的SubSearchViewMgr

结束如果

返回SubSrchMgr.GetView(colname)

Case SearchMgrTables .Contacts

如果ContactSrchMgr什么都没有那么

ContactSrchMgr =新的ContactSearchViewMgr

结束如果

返回ContactSrchMgr.GetView( colname)

Case SearchMgrTables.Invoices

我f OpenInvSrchMgr什么都没有

OpenInvSrchMgr =新的OpenInvSearchViewMgr

结束如果

返回OpenInvSrchMgr.GetView(colname)

结束选择

结束函数


公共函数查找(ByVal表作为SearchMgrTables,ByVal val作为

字符串)作为整数

选择案例表

案例SearchMgrTables.Subscriptions

如果SubSrchMgr IsNot Nothing那么

返回搜索(SubSrchMgr.CurrentView,val ,

SubSrchMgr.CurrentColumnNum)

结束如果

Case SearchMgrTables.Contacts

如果ContactSrchMgr IsNot Nothing那么

返回搜索(ContactSrchMgr.CurrentView,val,

ContactSrchMgr.CurrentColumnNum)

结束如果

Case SearchMgrTables.Invoices

如果OpenInvSrchMgr IsNot Nothing那么

返回搜索(OpenInvSrchMgr.CurrentView,val,

OpenInvSrchMgr.CurrentColumnNum)

结束如果

结束选择

'抛出新的ArgumentException(你必须先选择一个视图才能获得
寻找。)

结束功能


我评论出投掷使Seek函数看起来的语句

与GetView函数相同。但IDE只抱怨

GetView功能。

任何想法?

Terry

I know that this is just a warning message, but I wonder why the IDE flags
the first function with a warning, but not the second one. The warning
message is :
Function ''GetView'' doesn''t return a value on all code paths. A null
reference exception could occur at run time when the result is used.
Here is the code:
__________________________________________________ ____________________
Public Class SearchMgr
Public Enum SearchMgrTables
Subscriptions
Contacts
Invoices
End Enum
..
..
..
Public Function GetView(ByVal table As SearchMgrTables, ByVal colname As
String) As DataView
Select Case table
Case SearchMgrTables.Subscriptions
If SubSrchMgr Is Nothing Then
SubSrchMgr = New SubSearchViewMgr
End If
Return SubSrchMgr.GetView(colname)
Case SearchMgrTables.Contacts
If ContactSrchMgr Is Nothing Then
ContactSrchMgr = New ContactSearchViewMgr
End If
Return ContactSrchMgr.GetView(colname)
Case SearchMgrTables.Invoices
If OpenInvSrchMgr Is Nothing Then
OpenInvSrchMgr = New OpenInvSearchViewMgr
End If
Return OpenInvSrchMgr.GetView(colname)
End Select
End Function

Public Function Seek(ByVal table As SearchMgrTables, ByVal val As
String) As Integer
Select Case table
Case SearchMgrTables.Subscriptions
If SubSrchMgr IsNot Nothing Then
Return Search(SubSrchMgr.CurrentView, val,
SubSrchMgr.CurrentColumnNum)
End If
Case SearchMgrTables.Contacts
If ContactSrchMgr IsNot Nothing Then
Return Search(ContactSrchMgr.CurrentView, val,
ContactSrchMgr.CurrentColumnNum)
End If
Case SearchMgrTables.Invoices
If OpenInvSrchMgr IsNot Nothing Then
Return Search(OpenInvSrchMgr.CurrentView, val,
OpenInvSrchMgr.CurrentColumnNum)
End If
End Select
''Throw New ArgumentException("You must select a view before you can
seek.")
End Function

I commented out the "Throw" statement to make the Seek function look
identical to the GetView function. But the IDE only complains about the
GetView function.
Any Ideas?
Terry

推荐答案

嗨Terry,


在你的GetView函数中,如果表格与三种情况中的一种不匹配你

有,然后返回将为null。你的返回是一个引用类型,

可以为null。


在你的Seek函数中,如果表格与三种情况中的一种不匹配你

有,那么返回将为零,因为它是一个整数。在这种情况下,你的回报是

值类型。


J


" Terry" < Te **** @ nospam.nospamwrote in message

news:07 ************************** ******** @ microsof t.com ...
Hi Terry,

In your GetView function, if table doesn''t match one of the three cases you
have, then the return will be null. Your return is a reference type, which
can be null.

In your Seek function, if table doesn''t match one of the three cases you
have, then the return will be zero because it is an Integer. Your return is
a value type in this case.

J

"Terry" <Te****@nospam.nospamwrote in message
news:07**********************************@microsof t.com...

>我知道这只是一条警告信息,但我想知道IDE的原因标志

带警告的第一个函数,但不是第二个函数。警告

消息是:

函数''GetView''在所有代码路径上都没有返回值。使用结果时,可能会在运行时发生null

引用异常。

以下是代码:

__________________________________________________ ____________________

Public Class SearchMgr

Public Enum SearchMgrTables

订阅

联系人

发票

结束枚举







公共函数GetView(ByVal表作为SearchMgrTables,ByVal colname

As

String)As DataView

Select Case table

Case SearchMgrTables.Subscriptions

如果SubSrchMgr什么都没有那么

SubSrchMgr =新的SubSearchViewMgr

结束如果

返回SubSrchMgr.GetView(colname)

Case SearchMgrTables.Contacts

如果ContactSrchMgr什么都没有那么

ContactSrchMgr =新的ContactSearchViewMgr

结束如果

返回ContactSrchMgr.GetView(colname)

Case SearchMgrTables.Invoices

如果OpenInvSrchMgr什么都没有

OpenInvSrchMgr =新的OpenInvSearchViewMgr

结束如果

返回OpenInvSrchMgr.GetView(colname)

结束选择

结束函数


公共函数查找(ByVal表作为SearchMgrTables,ByVal val作为

字符串)作为整数

Select Case table

Case SearchMgrTables.Subscriptions

如果SubSrchMgr IsNot Nothing那么

返回搜索(SubSrchMgr.CurrentView,val,

SubSrchMgr.CurrentColumnNum)

结束如果

Case SearchMgrTables.Contacts

如果ContactSrchMgr IsNot Noth那么

返回搜索(ContactSrchMgr.CurrentView,val,

ContactSrchMgr.CurrentColumnNum)

结束如果

案例SearchMgrTables.Invoices

如果OpenInvSrchMgr IsNot Nothing那么

返回搜索(OpenInvSrchMgr.CurrentView,val,

OpenInvSrchMgr.CurrentColumnNum)

结束如果

结束选择

''抛出新的ArgumentException("你必须先选择一个视图才能获得
寻找。) ;)

结束功能


我注释掉了投掷使Seek函数看起来的语句

与GetView函数相同。但IDE只抱怨

GetView功能。

任何想法?

特里
>I know that this is just a warning message, but I wonder why the IDE flags
the first function with a warning, but not the second one. The warning
message is :
Function ''GetView'' doesn''t return a value on all code paths. A null
reference exception could occur at run time when the result is used.
Here is the code:
__________________________________________________ ____________________
Public Class SearchMgr
Public Enum SearchMgrTables
Subscriptions
Contacts
Invoices
End Enum
.
.
.
Public Function GetView(ByVal table As SearchMgrTables, ByVal colname
As
String) As DataView
Select Case table
Case SearchMgrTables.Subscriptions
If SubSrchMgr Is Nothing Then
SubSrchMgr = New SubSearchViewMgr
End If
Return SubSrchMgr.GetView(colname)
Case SearchMgrTables.Contacts
If ContactSrchMgr Is Nothing Then
ContactSrchMgr = New ContactSearchViewMgr
End If
Return ContactSrchMgr.GetView(colname)
Case SearchMgrTables.Invoices
If OpenInvSrchMgr Is Nothing Then
OpenInvSrchMgr = New OpenInvSearchViewMgr
End If
Return OpenInvSrchMgr.GetView(colname)
End Select
End Function

Public Function Seek(ByVal table As SearchMgrTables, ByVal val As
String) As Integer
Select Case table
Case SearchMgrTables.Subscriptions
If SubSrchMgr IsNot Nothing Then
Return Search(SubSrchMgr.CurrentView, val,
SubSrchMgr.CurrentColumnNum)
End If
Case SearchMgrTables.Contacts
If ContactSrchMgr IsNot Nothing Then
Return Search(ContactSrchMgr.CurrentView, val,
ContactSrchMgr.CurrentColumnNum)
End If
Case SearchMgrTables.Invoices
If OpenInvSrchMgr IsNot Nothing Then
Return Search(OpenInvSrchMgr.CurrentView, val,
OpenInvSrchMgr.CurrentColumnNum)
End If
End Select
''Throw New ArgumentException("You must select a view before you can
seek.")
End Function

I commented out the "Throw" statement to make the Seek function look
identical to the GetView function. But the IDE only complains about the
GetView function.
Any Ideas?
Terry



嗨约翰,

好​​的,我明白了。太糟糕了,它不够聪明,无法弄清楚选择的

案例是详尽无遗的。

-

特里

约翰写道:
Hi John,
Ok, I get it. Too bad its not smart enough to figure out that the select
case was exhaustive.
--
Terry
"John" wrote:

嗨Terry,


在你的GetView函数中,如果表格与三种情况中的一种不匹配你

有,那么返回将为null。你的返回是一个引用类型,

可以为null。


在你的Seek函数中,如果表格与三种情况中的一种不匹配你

有,那么返回将为零,因为它是一个整数。在这种情况下,你的回报是

值类型。


J


" Terry" < Te **** @ nospam.nospamwrote in message

news:07 ************************** ******** @ microsof t.com ...
Hi Terry,

In your GetView function, if table doesn''t match one of the three cases you
have, then the return will be null. Your return is a reference type, which
can be null.

In your Seek function, if table doesn''t match one of the three cases you
have, then the return will be zero because it is an Integer. Your return is
a value type in this case.

J

"Terry" <Te****@nospam.nospamwrote in message
news:07**********************************@microsof t.com...

我知道这只是一条警告信息,但我想知道为什么IDE会标记

带警告的第一个函数,但不是第二个函数。警告

消息是:

函数''GetView''在所有代码路径上都没有返回值。使用结果时,可能会在运行时发生null

引用异常。

以下是代码:

__________________________________________________ ____________________

Public Class SearchMgr

Public Enum SearchMgrTables

订阅

联系人

发票

结束枚举







公共函数GetView(ByVal表作为SearchMgrTables,ByVal colname

As

String)As DataView

Select Case table

Case SearchMgrTables.Subscriptions

如果SubSrchMgr什么都没有那么

SubSrchMgr =新的SubSearchViewMgr

结束如果

返回SubSrchMgr.GetView(colname)

Case SearchMgrTables.Contacts

如果ContactSrchMgr什么都没有那么

ContactSrchMgr =新的ContactSearchViewMgr

结束如果

返回ContactSrchMgr.GetView(colname)

Case SearchMgrTables.Invoices

如果OpenInvSrchMgr什么都没有那么

OpenInvSrchMgr =新的OpenInvSearchViewMgr

结束如果

返回OpenInvSrchMgr.GetView(colname)

结束选择

结束功能

公共功能寻求(ByVal表作为SearchMgrTables,ByVal val As

String)As整数

选择案例表

案例SearchMgrTables.Subscriptions

如果SubSrchMgr IsNot Nothing那么

返回搜索(SubSrchMgr。 CurrentView,val,

SubSrchMgr.CurrentColumnNum)

结束如果

Case SearchMgrTables.Contacts

如果ContactSrchMgr IsNot Nothing那么

返回搜索(ContactSrchMgr.CurrentView,val,

ContactSrchMgr.CurrentColumnNum)

结束如果

Case SearchMgrTables.Invoices

如果OpenInvSrchMgr IsNot Nothing那么

返回搜索(OpenInvSrchMgr.CurrentView,val,

OpenInvSrchMgr.CurrentColumnNum)

结束如果

结束选择

''抛出新的ArgumentException("你必须先选择一个视图才能获得
寻求。)

结束功能


我注释掉了投掷使Seek函数看起来的语句

与GetView函数相同。但IDE只抱怨

GetView功能。

任何想法?

特里
I know that this is just a warning message, but I wonder why the IDE flags
the first function with a warning, but not the second one. The warning
message is :
Function ''GetView'' doesn''t return a value on all code paths. A null
reference exception could occur at run time when the result is used.
Here is the code:
__________________________________________________ ____________________
Public Class SearchMgr
Public Enum SearchMgrTables
Subscriptions
Contacts
Invoices
End Enum
.
.
.
Public Function GetView(ByVal table As SearchMgrTables, ByVal colname
As
String) As DataView
Select Case table
Case SearchMgrTables.Subscriptions
If SubSrchMgr Is Nothing Then
SubSrchMgr = New SubSearchViewMgr
End If
Return SubSrchMgr.GetView(colname)
Case SearchMgrTables.Contacts
If ContactSrchMgr Is Nothing Then
ContactSrchMgr = New ContactSearchViewMgr
End If
Return ContactSrchMgr.GetView(colname)
Case SearchMgrTables.Invoices
If OpenInvSrchMgr Is Nothing Then
OpenInvSrchMgr = New OpenInvSearchViewMgr
End If
Return OpenInvSrchMgr.GetView(colname)
End Select
End Function

Public Function Seek(ByVal table As SearchMgrTables, ByVal val As
String) As Integer
Select Case table
Case SearchMgrTables.Subscriptions
If SubSrchMgr IsNot Nothing Then
Return Search(SubSrchMgr.CurrentView, val,
SubSrchMgr.CurrentColumnNum)
End If
Case SearchMgrTables.Contacts
If ContactSrchMgr IsNot Nothing Then
Return Search(ContactSrchMgr.CurrentView, val,
ContactSrchMgr.CurrentColumnNum)
End If
Case SearchMgrTables.Invoices
If OpenInvSrchMgr IsNot Nothing Then
Return Search(OpenInvSrchMgr.CurrentView, val,
OpenInvSrchMgr.CurrentColumnNum)
End If
End Select
''Throw New ArgumentException("You must select a view before you can
seek.")
End Function

I commented out the "Throw" statement to make the Seek function look
identical to the GetView function. But the IDE only complains about the
GetView function.
Any Ideas?
Terry






Terry,


由于你的案例方法不符合案件中的任何陈述,你不是

返回一些东西。

案例选择后的回复可能会解决这个问题。


Cor


Terry < Te **** @ nospam.nospamschreef in bericht

news:07 ************************** ******** @ microsof t.com ...
Terry,

As your case methode does not fulfil any statement in the case, you are not
returning something.
A return after the case select will probably solve this.

Cor

"Terry" <Te****@nospam.nospamschreef in bericht
news:07**********************************@microsof t.com...

>我知道这只是一条警告信息,但我想知道IDE的原因标志

带警告的第一个函数,但不是第二个函数。警告

消息是:

函数''GetView''在所有代码路径上都没有返回值。使用结果时,可能会在运行时发生null

引用异常。

以下是代码:

__________________________________________________ ____________________

Public Class SearchMgr

Public Enum SearchMgrTables

订阅

联系人

发票

结束枚举







公共函数GetView(ByVal表作为SearchMgrTables,ByVal colname

As

String)As DataView

Select Case table

Case SearchMgrTables.Subscriptions

如果SubSrchMgr什么都没有那么

SubSrchMgr =新的SubSearchViewMgr

结束如果

返回SubSrchMgr.GetView(colname)

Case SearchMgrTables.Contacts

如果ContactSrchMgr什么都没有那么

ContactSrchMgr =新的ContactSearchViewMgr

结束如果

返回ContactSrchMgr.GetView(colname)

Case SearchMgrTables.Invoices

如果OpenInvSrchMgr什么都没有

OpenInvSrchMgr =新的OpenInvSearchViewMgr

结束如果

返回OpenInvSrchMgr.GetView(colname)

结束选择

结束函数


公共函数查找(ByVal表作为SearchMgrTables,ByVal val作为

字符串)作为整数

Select Case table

Case SearchMgrTables.Subscriptions

如果SubSrchMgr IsNot Nothing那么

返回搜索(SubSrchMgr.CurrentView,val,

SubSrchMgr.CurrentColumnNum)

结束如果

Case SearchMgrTables.Contacts

如果ContactSrchMgr IsNot Noth那么

返回搜索(ContactSrchMgr.CurrentView,val,

ContactSrchMgr.CurrentColumnNum)

结束如果

案例SearchMgrTables.Invoices

如果OpenInvSrchMgr IsNot Nothing那么

返回搜索(OpenInvSrchMgr.CurrentView,val,

OpenInvSrchMgr.CurrentColumnNum)

结束如果

结束选择

''抛出新的ArgumentException("你必须先选择一个视图才能获得
寻找。) ;)

结束功能


我注释掉了投掷使Seek函数看起来的语句

与GetView函数相同。但IDE只抱怨

GetView功能。

任何想法?

特里
>I know that this is just a warning message, but I wonder why the IDE flags
the first function with a warning, but not the second one. The warning
message is :
Function ''GetView'' doesn''t return a value on all code paths. A null
reference exception could occur at run time when the result is used.
Here is the code:
__________________________________________________ ____________________
Public Class SearchMgr
Public Enum SearchMgrTables
Subscriptions
Contacts
Invoices
End Enum
.
.
.
Public Function GetView(ByVal table As SearchMgrTables, ByVal colname
As
String) As DataView
Select Case table
Case SearchMgrTables.Subscriptions
If SubSrchMgr Is Nothing Then
SubSrchMgr = New SubSearchViewMgr
End If
Return SubSrchMgr.GetView(colname)
Case SearchMgrTables.Contacts
If ContactSrchMgr Is Nothing Then
ContactSrchMgr = New ContactSearchViewMgr
End If
Return ContactSrchMgr.GetView(colname)
Case SearchMgrTables.Invoices
If OpenInvSrchMgr Is Nothing Then
OpenInvSrchMgr = New OpenInvSearchViewMgr
End If
Return OpenInvSrchMgr.GetView(colname)
End Select
End Function

Public Function Seek(ByVal table As SearchMgrTables, ByVal val As
String) As Integer
Select Case table
Case SearchMgrTables.Subscriptions
If SubSrchMgr IsNot Nothing Then
Return Search(SubSrchMgr.CurrentView, val,
SubSrchMgr.CurrentColumnNum)
End If
Case SearchMgrTables.Contacts
If ContactSrchMgr IsNot Nothing Then
Return Search(ContactSrchMgr.CurrentView, val,
ContactSrchMgr.CurrentColumnNum)
End If
Case SearchMgrTables.Invoices
If OpenInvSrchMgr IsNot Nothing Then
Return Search(OpenInvSrchMgr.CurrentView, val,
OpenInvSrchMgr.CurrentColumnNum)
End If
End Select
''Throw New ArgumentException("You must select a view before you can
seek.")
End Function

I commented out the "Throw" statement to make the Seek function look
identical to the GetView function. But the IDE only complains about the
GetView function.
Any Ideas?
Terry


这篇关于有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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