what's better
var s = (string)reader[0]
or
var s = Convert.ToString(reader[0])
?
Here both the methods are used to convert the string but the basic difference between them is: "Convert" function handles NULLS, while "i. ToString()" does not it will throw a NULL reference exception error. So as good coding practice using "convert" is always safe.
Convert the specified value to its equivalent string using the ToString() method. Initialize a bool value. bool boolVal = false; Now, to convert it to a string, use the ToString() method.
ToString is the major formatting method in the . NET Framework. It converts an object to its string representation so that it is suitable for display.
.ToString()It will not handle NULL values; it will throw a NULL reference exception error.
I'd say reader.GetString(0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With