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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:10:11+00:00 2026-05-21T23:10:11+00:00

Well, a few months ago I asked a similar question about C and C++

  • 0

Well, a few months ago I asked a similar question about C and C++, but I’ve been paying more attention to C# lately due to the whole “Windows Phone” thing.

So, in C#, should one bother to check against NULL at method boundaries? I think this is different than in C and C++, because in C# one generally can determine whether a given reference is valid — the compiler will prevent one from passing uninitialized references anywhere, and therefore the only remaining possible mistake is for it to be null. Furthermore, there’s a specific exception defined inside the .NET Framework for these things, the ArgumentNullException, which seems to codify what programmers think they should be getting when an invalid null was passed.

My personal opinion is once again that a caller doing this is broken, and that said caller should have NREs thrown at them until the end of days. However, I’m much less sure about this than I am in native code land — C# has quite a different programming style in places compared to either C or C++ in this regard.

So… should you check for null parameters in C# methods?

  • 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-21T23:10:11+00:00Added an answer on May 21, 2026 at 11:10 pm

    Yes, check for them. Preferably use Code Contracts to tell the caller that you require non-null parameters

    void Foo(Bar bar) {
        Contract.Requires(bar != null);
    }
    

    This is particularly advantageous since the client can see exactly what is required of parameters.

    If you can’t use Code Contracts, use a guard clause

    void Foo(Bar bar) {
        Guard.Against<ArgumentNullException>(bar == null);
    }
    

    Fail fast.

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

Sidebar

Related Questions

I've asked here a ton of questions about WSAAsyncSelect and NET.Few months ago I
I posted a question a few months ago about sharing resource dictionaries across assemblies
Well from last few months, i am looking for one solution, but couldn't find
I've been programming objective-C for a few months now and have done pretty well
A Chrome extension I built a few months ago has been working fine until
Few months ago I was programming a simple application with som other guy in
after a few months learning a bit about rails and making some stuff local,
So at work I have been working for a few months on a OPOS
Quick personal background: I was hired a few months ago as the sole .NET
For the past few months, I've been showing/hiding things on the edge of the

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.