aaaaaaaaaaaa aaaaaaaaaaaa - 1 month ago 9
Vb.net Question

Why does this function not return a value on all code paths?

Consider:

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


Why does
ViewPropertyCast
not return a value on all code paths?

Answer

You have no default. What if it matches none of the cases? Add a default that returns an error, or put one after the select. You may be sure you'll never be passed anything else, but the compiler isn't.