Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8530553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:16:29+00:00 2026-06-11T09:16:29+00:00

I am currently fighting an old api and I am facing the following problem:

  • 0

I am currently fighting an old api and I am facing the following problem: I get runtime exceptions when I try to cast an Object to an array of Objects when the values are nullable dates.

Module Module1
    Sub Main()
        Console.WriteLine(Misc.dateCast(New Nullable(Of DateTime)()))
        Console.WriteLine(Misc.tabledateCast(New Nullable(Of DateTime)() {New DateTime()}))
    End Sub
End Module

Module Misc
    Function dateCast(ByVal val As Nullable(Of DateTime)) As Object
        Return CType(val, Object)
    End Function

    Function tabledateCast(ByVal val As Object) As Object()
        Return CType(val, IEnumerable(Of Object)).Cast(Of Object).ToArray
    End Function
End Module

The first cast is working, but not the second. How to cast successfully to an array of objects?

I cannot use CType(val, IEnumerable(Of Nullable(Of DateTime))) because the function may get arrays of other types.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T09:16:30+00:00Added an answer on June 11, 2026 at 9:16 am

    Looks like you’ve got two choices:

    1) If the arrays themselves are type-safe, you can genericize the method so that it knows what to cast to before casting to an object – not the nicest code to look at, especially in VB.NET:

    Module Module1
        Sub Main()
            Console.WriteLine(Misc.tabledateCast(Of Nullable(Of DateTime))(New Nullable(Of DateTime)() {New DateTime()}))
        End Sub
    End Module
    
    Module Misc
        Function tabledateCast(Of T)(ByVal val As Object) As Object()
            Return CType(val, IEnumerable(Of T)).Cast(Of Object).ToArray
        End Function
    End Module
    

    2) Laoujin’s link, where you do a non-generic IEnumerable cast first:

    Module Module1
        Sub Main()
            Console.WriteLine(Misc.tabledateCast(New Nullable(Of DateTime)() {New DateTime()}))
        End Sub
    End Module
    
    Module Misc
        Function tabledateCast(ByVal val As Object) As Object()
            Return CType(val, IEnumerable).Cast(Of Object).ToArray
        End Function
    End Module
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently fighting Google Chrome on the following action: location.href = url location.replace(url)
I'm currently fighting with IE. Before I get some rants about tables I know
I am currently fighting to work with the reasmpling function from pandas 0.8.0b1. For
I'm currently fighting with Vim, I can't seem to make the indentation options do
I'm currently fighting a fierce battle with an interface I'm trying to put together.
Being a softie, I'm currently fighting some hardware techies on a hardware detection mechanism.
I am fighting with Xcode 4 workspaces. Currently Xcode 4 wins. Thus, my situation:
I'm fighting with pointers :(. I try to make a function which do something
Currently learning Scheme/Racket and have problem running this piece of code. (if (or (<
For the last 2 hours I have been fighting with this problem and trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.