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

  • Home
  • SEARCH
  • 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 5995897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:01:34+00:00 2026-05-23T00:01:34+00:00

I recently asked this question on the subject, which was closed as a duplicate

  • 0

I recently asked this question on the subject, which was closed as a duplicate of this one – as was this one before mine. However, I want to ask a more specific question on a corner case that I feel none of the above questions, or their answers, really covers:

How should an extension method that doesn’t really need an instance react to null references?

An example (where the answer is obvious) would be the .IsNullOrEmpty() (which of course should just return true on a null reference), but I believe there might be other cases where it makes sense to call an extension method on an object that might be null.

Another example could be a variation of the method I outlined in my other question, if we for a minute assume that the foreach loop will not throw on a null collection (I know it does, but imagine it doesn’t just as a thought experiment).

What would be best practice here? Should we check for null and throw ArgumentNullException anyway, or does it depend on the case? If it does depend on the case, on what criteria should we decide what to do?

  • 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-05-23T00:01:35+00:00Added an answer on May 23, 2026 at 12:01 am

    Personally, I have an issue with extension methods that do not throw on a null instance. I understand that extension methods are syntactic sugar for static methods. However, their use is like that of an instance method. Hence, I believe they should behave as if they were an instance method and throw when the “this” instance is null.

    This is a maintainability concern for me. For a newcomer to a code base who does not know whether a method is on the actual type or is an extension method, seeing a method like IsNull() would be disconcerting because it simply doesn’t make any sense.

    So, that is my two cents: a complete utter personal opinion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Further to this question and this one that I asked more recently but without
I was asked this question recently in a test, which I didn't pass. For
I was asked this question in one of my interviews with a MNC recently.
Possible Duplicate: difference between destructor and garbage collector Recently i asked this question ,
This question was recently asked to me in an interview for which i went
I recently asked this question on here and got the answer. However I'm now
This question is very similar to one I recently asked: Python threading- returning control
I was recently asked this question in one of my telephonic interview. There is
I recently asked this question: MS SQL share identity seed amongst tables (Many people
This was asked in my Google interview recently and I offered an answer which

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.