By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,627 Members | 2,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,627 IT Pros & Developers. It's quick & easy.

Casting up?

P: n/a
Can someone explain to me why I must explicitly cast UP a
class heiarchy when using option explicit? For instance,
I have a typed dataset (which is derived from the DataSet
class) and I'm passing this typed dataset to a function
that requires a system.data.dataset as an argument. The
compiler complains about a type mismatch and won't let me
compile until I pass the typed dataset as
CType(myTypedDataSet, DataSet). I find this very bizarre.
Maybe I'm really missing something. Any explanation would
be appreciated.

Rob Reagan
Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Rob,
CType(myTypedDataSet, DataSet). I find this very bizarre. How is the variable myTypedDataSet defined?

If its defined as:

Dim myTypedDataSet As TypedDataSet

then the CType is not needed, as TypedDataSet is a DataSet and the compiler
knows it.

However if myTypedDataSet is defined as:

Dim myTypedDataSet As Object

Then the CType is needed, although I prefer DirectCast (DirectCast is used
for Casting, CType is used for Converting). It is needed, as an object can
contain any type of variable, and you need to let the compiler know
specifically which type you want.

So to better answer your question we need to know how you defined the
myTypedDataSet variable.

Hope this helps
Jay

"Rob Reagan" <ro*@digital-labs.biz> wrote in message
news:01****************************@phx.gbl... Can someone explain to me why I must explicitly cast UP a
class heiarchy when using option explicit? For instance,
I have a typed dataset (which is derived from the DataSet
class) and I'm passing this typed dataset to a function
that requires a system.data.dataset as an argument. The
compiler complains about a type mismatch and won't let me
compile until I pass the typed dataset as
CType(myTypedDataSet, DataSet). I find this very bizarre.
Maybe I'm really missing something. Any explanation would
be appreciated.

Rob Reagan

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.