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 8551331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:10:23+00:00 2026-06-11T14:10:23+00:00

Got an interesting oddity – thought someone might be able to help. This came

  • 0

Got an interesting oddity – thought someone might be able to help.

This came out of some fun with nullable types from this question:

How to check if an object is nullable?

Option Strict On

Module Test
  ' Call this overload 1
  <Extension()>
  Function IsNullable(obj As ValueType) As Boolean
    Return False
  End Function

  ' Call this overload 2
  <Extension()>
  Function IsNullable(Of T As {Structure})(obj As Nullable(Of T)) As Boolean
    Return True
  End Function

  Sub Test() 
    ' a is an integer!
    Dim a As Integer = 123

    ' calling IsNullable as an extension method calls overload 1 and returns false
    Dim result1 As Boolean = a.IsNullable()

    ' calling IsNullable as method calls overload 2 and returns true
    Dim result2 As Boolean = IsNullable(a)

    ' why? surely the compiler should treat both those calls as equivalent
  End Sub
End Module

I would expect that both calls to IsNullable would be treated the same by the compiler, but that is not the case. The extension method call uses a different overload to the normal method call even though the argument “a” is unchanged.

My question is why? What makes the compiler change its mind between the two calls?

FTR: We are using Visual Studio 2010, .NET Framework 4.

  • 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-11T14:10:24+00:00Added an answer on June 11, 2026 at 2:10 pm

    I think this is a bug, or at least a VB.NET “feature”. (I’m just not sure which of VB.NET or C# is wrong.)

    I have tried in LINQPad 4 (because that’s what I’ve got on the machine I’m using) and for C# I got False for both results, for every value type and enum except for Nullable types, of course.

    Whereas for VB.NET I get the False and True for all value types and enums, except for Nullable types, and ValueType and [Enum] which return False, False because you can’t have a ValueType? or [Enum]?. With Option Strict Off, Object causes late binding, and fails at runtime to locate either overload, but the second result is False also because you can’t have Object?.

    For completeness, Nullable types return True, True for both languages as expected.

    The fact that C# is doing something different (assuming my test is correct) confirms the reference to the C# “Better Conversion” check is wrong (or being misread at least – in that C# is not doing what is being interpreted as why VB.NET is doing what it is doing).

    However, I do agree that the issue is probably related to the implicit conversion to Nullable(Of T) existing and somehow being a higher priority to the implicit conversion to ValueType.

    Here’s my LINQPad 4 “Query” (C# Program):

    void Main()
    {
        Test.test();
    }
    
    // Define other methods and classes here
    static class Test
    {
        static bool IsNullable(this ValueType obj)
        {
            return false;
        }
    
        static bool IsNullable<T>(this T? obj) where T:struct
        {
            return true;
        }
    
        public static void test()
        {
            int x = 42;
    
            bool result1 = x.IsNullable();
            bool result2 = IsNullable(x);
    
            result1.Dump("result1");
            result2.Dump("result2");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This turns out to be really interesting, I have got my question and replies
(I asked this question in another way , and got some interesting responses but
I got some interesting ideas and criticism from this , this and this post
I've got an interesting SQL puzzle I haven't been able to solve, hopefully one
In recent talk with client, we got an interesting question, if we are able
In a previous question ( Get object call hierarchy ), I got this interesting
I recently asked this question https://softwareengineering.stackexchange.com/questions/129076/go-instead-of-c-c-with-cgo and got some very interesting input. However there's
I've got a powershell script that monitors a log file, filters out the interesting
Got asked this interesting interview question today. Explain in detail the process by which
So I've got an interesting problem that I need help with faster than I

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.