考虑:
Private Function ViewPropertyCast(ByVal type As String) As String
Select Case type
Case "smallint"
Return "Short"
Case "nvarchar"
Return "String"
Case "int"
Return "Integer"
Case "float"
Return "Double"
Case "datetime"
Return "Date"
Case "bigint"
Return "Long"
Case "ntext"
Return "String"
Case "bit"
Return "Boolean"
Case "uniqueidentifier"
Return "Guid"
End Select
End Function
为什么ViewPropertyCast
不会在所有代码路径上返回值?
答案 0 :(得分:5)
因为如果type
none 列出了这些内容,它只会降到底部,而不会返回任何内容。
尝试类似:
Private Function ViewPropertyCast(ByVal type As String) As String
Select Case type
Case "smallint"
Return "Short"
Case "nvarchar"
Return "String"
Case "int"
Return "Integer"
Case "float"
Return "Double"
Case "datetime"
Return "Date"
Case "bigint"
Return "Long"
Case "ntext"
Return "String"
Case "bit"
Return "Boolean"
Case "uniqueidentifier"
Return "Guid"
End Select
Return "NoIdea" ' <-- Added this bit '
End Function
答案 1 :(得分:3)
您没有默认值。如果它与所有情况都不匹配怎么办?添加一个返回错误的默认值,或者在select之后添加一个错误。您可能确定永远不会传递任何其他内容,但编译器不会。
答案 2 :(得分:1)
您没有默认情况。如果我传递“foo”,则该函数无法返回值。