CType?

A

Arpan

The syntax of the function CType, as stated in the .NET 2 SDK
Documentation, is

CType(expression, typename)

The Documentation also states that

CType is compiled inline which means that the conversion code is part
of the code that evaluates the expression.

Can someone please explain me (with an example preferably) what does
the above statement mean? I know that CType is used for type casting.

In the following line

CType(ea.Item.Cells(1).Controls(0), TextBox).Text

if I am not mistaken, "ea.Item.Cells(1).Controls(0)" is the expression
but here CType is casting the expression from what type to what type?
Secondly, what is ".Text" doing there at the very end of the line?

Thanks,

Arpan
 
N

Nathan Sokalski

First, because ea.Item.Cells(1).Controls(0) is a System.Web.UI.Control and
TextBox is a System.Web.UI.WebControls.TextBox, the expression is being cast
from a System.Web.UI.Control to a System.Web.UI.WebControls.TextBox. The
..Text at the end is the Text property of the TextBox object that is returned
by the CType function. Hopefully this clears things up.
 
G

Guest

Regarding the definition of CType, it is not a function, but a macro (ditto
for CStr, CInt, etc.) - the VB compiler substitutes the corresponding code
in-line when the code is compiled to IL.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
C# Code Metrics: Quick metrics for C#
 
A

Arpan

the VB compiler substitutes the corresponding code
in-line when the code is compiled to IL.

David, could you please clarify the statement "substitutes the
corresponding code in-line when the code is compiled to MSIL"
especially "in-line"? Please try to be as transparent as possible :)

Thanks,

Regards,

Arpan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top