is this redundant...

G

Guest

hey all,

Private Property mEmployeeDataset() As DsHRLIBR24
Get
Return DirectCast(Session("oDs"), DsHRLIBR24)
End Get
Set(ByVal Value As DsHRLIBR24)
Session("oDs") = Value
End Set
End Property

Is my DirectCast needed in this case?

thanks,
rodchar
 
G

George

If you will be able to compile without it then no.

I do not know much about VB.NET in C# you must you cast in cases like that.

George.

hey all,

Private Property mEmployeeDataset() As DsHRLIBR24
Get
Return DirectCast(Session("oDs"), DsHRLIBR24)
End Get
Set(ByVal Value As DsHRLIBR24)
Session("oDs") = Value
End Set
End Property

Is my DirectCast needed in this case?

thanks,
rodchar
 
K

Kevin Spencer

Is my DirectCast needed in this case?

Not needed, but certainly acceptable. And not redundant.

The difference between CType and DirectCast is that CType will work as long
as there is a valid conversion defined for the expression and the object
type specified, whereas DirectCast will only work if the run-time types are
the same. For example:

Dim i As Integer = CType("23", Integer) 'Fine
Dim i As Integer = DirectCast("23", Integer) ' Exception

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
G

Guest

thanks everyone for the help.

Kevin Spencer said:
Not needed, but certainly acceptable. And not redundant.

The difference between CType and DirectCast is that CType will work as long
as there is a valid conversion defined for the expression and the object
type specified, whereas DirectCast will only work if the run-time types are
the same. For example:

Dim i As Integer = CType("23", Integer) 'Fine
Dim i As Integer = DirectCast("23", Integer) ' Exception

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 

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

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top