T
tinman
Hi...
I have the following two excerpts from a method. It basically reads data
from a DataReader and
loads it in a collection.
Excerpt A:
********
With ProjectData
While .Read
Me.Add(DirectCast(.Item("project_id"), Guid), _
DirectCast(.Item("start_date"), DateTime), _
DirectCast(.Item("end_date"), DateTime), _
DirectCast(.Item("priority"), Integer), _
DirectCast(.Item("description"), String), _
DirectCast(.Item("project_manager"), String)
End While
End With
Excerpt B:
********
With ProjectData
While .Read
Me.Add(.Item("project_id"),
.Item("start_date"),
.Item("end_date"),
.Item("priority"),
.Item("description"),
.Item("project_manager")
End While
End With
Question:
Does automatic casting outperform explicit casting ? When I run ILDASM, I
find
that at each DirectCast, there is unboxing but in Excerpt B, there isn't
any.
Snippets of the ILDASM for Excerpt A and B below:
ILDASM (Excerpt A)
****************
IL_0098: ldloc.2
IL_0099: ldstr "description"
IL_009e: callvirt instance object
XXX.Projects.XDataReader::get_Item(string)
IL_00a3: unbox [mscorlib]System.Int32
IL_00a8: ldobj [mscorlib]System.Int32
ILDASM (Excerpt B)
****************
IL_0092: ldloc.2
IL_0093: ldstr "description"
IL_0098: callvirt instance object
XXX.Projects.XDataReader::get_Item(string)
IL_009d: call int32
[Microsoft.VisualBasic]Microsoft.VisualBasic.CompilerServices.IntegerType::F
romObject(object)
Any pointers to articles that explain what goes on "under the hood" with
regards to
casting would be much appreciated as well.
Cheers !
I have the following two excerpts from a method. It basically reads data
from a DataReader and
loads it in a collection.
Excerpt A:
********
With ProjectData
While .Read
Me.Add(DirectCast(.Item("project_id"), Guid), _
DirectCast(.Item("start_date"), DateTime), _
DirectCast(.Item("end_date"), DateTime), _
DirectCast(.Item("priority"), Integer), _
DirectCast(.Item("description"), String), _
DirectCast(.Item("project_manager"), String)
End While
End With
Excerpt B:
********
With ProjectData
While .Read
Me.Add(.Item("project_id"),
.Item("start_date"),
.Item("end_date"),
.Item("priority"),
.Item("description"),
.Item("project_manager")
End While
End With
Question:
Does automatic casting outperform explicit casting ? When I run ILDASM, I
find
that at each DirectCast, there is unboxing but in Excerpt B, there isn't
any.
Snippets of the ILDASM for Excerpt A and B below:
ILDASM (Excerpt A)
****************
IL_0098: ldloc.2
IL_0099: ldstr "description"
IL_009e: callvirt instance object
XXX.Projects.XDataReader::get_Item(string)
IL_00a3: unbox [mscorlib]System.Int32
IL_00a8: ldobj [mscorlib]System.Int32
ILDASM (Excerpt B)
****************
IL_0092: ldloc.2
IL_0093: ldstr "description"
IL_0098: callvirt instance object
XXX.Projects.XDataReader::get_Item(string)
IL_009d: call int32
[Microsoft.VisualBasic]Microsoft.VisualBasic.CompilerServices.IntegerType::F
romObject(object)
Any pointers to articles that explain what goes on "under the hood" with
regards to
casting would be much appreciated as well.
Cheers !