there are an array of options for casting in VB.NET and I wanted to clarify my understanding.
DIRECTCAST
Please see the code below:
Dim p as New PostGraduate
Dim s as student = directcast(p,student)
This is a CAST rather than a conversion. Therefore the reference changes to a Student and the value is still a PostGraduate.
cstr and ctype
Please see the code below:
dim l as long=100
dim i as integer = cstr(l)
dim j as integer = ctype(l,integer)
These are both conversions so the reference and value changes to an integer. cstr and ctype are identical. cstr and ctype call Convert.ToString, Convert.ToInt etc behind the scenes. How is a custom object e.g. Student converted (Object.ToString?)
DataReader.getString (http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.getstring%28v=vs.110%29.aspx) and DataReader.getOrdinal (http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.getordinal%28v=vs.110%29.aspx)
When should these be used? Do they call convert.ToString behind the scenes?
I am confused why there are so many different ways to do the same thing.