Typing to Nullable (Of Date) vs typing to Date

J

JimLad

This is just an example of the crux of the problem:

CType(CObj("11/09/2009"), Date)
Returns date object as expected.

CType(CObj("11/09/2009"), Nullable(of Date))
In QuickWatch returns the string.
At runtime crashes out with invalid Cast.

Can someone explain the different behaviour to me please? I don't see
why one works and one doesn't.

Also assuming I have a gridview returning IOrderedDictionary, how do I
convert blanks strings to nothing and non-blank string to date? Do I
have to resort to IIF? Given that Nullable(of Date) can't cope with
different base types cast as objects I guess I'll have to...

In the case above I had a function returning a string, but when
'Nothing' was returned it got converted to an empty string. Then I
tried returning the string date or nothing in an object, but that
still didn't work.

I'm probably being a bit stupid. Apoplogies if the answer is simple...

James
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top