I usually avoid the built-in VB conversion functions (CStr, CDate, CBool, CInt, etc.) unless I need to do the actual conversion. If I just cast, say, from an object to a string, I usually use DirectCast or TryCast, assuming CStr, etc. Do some extra things that I don't need. But sometimes DirectCast syntax is a bit cumbersome, as in the following example.
Dim value1 As String Dim value2 As String Using cn As New SqlConnection(cnStr) Using cmd as New SqlCommmand(sqlStr, cn) Using reader = cmd.ExecuteReader() While reader.Read() value1 = DirectCast(reader("COLUMN1"), String) value2 = CStr(reader("COLUMN1")) End While End Using End Using End Using
SqlDataReader.Item returns the object that must be passed to String. CStr is easier to read, enter, and explain (IMO).
My question is, does it matter which one I use? Should I just go with CStr (and CDate and CBool, etc.) and not worry about the extra work that I assume that these functions are performed?
Is there any other drawback to using these features?
source share