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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:50:39+00:00 2026-05-26T22:50:39+00:00

In C, in order to test if a pointer is null we can do:

  • 0

In C, in order to test if a pointer is null we can do:

  • if (p != NULL)
  • if (p != 0)
  • if (p)

Why isn’t there any equivalent in C# that would allow us to do the following?

if (object)

instead of

if (object != null)
  • 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-26T22:50:40+00:00Added an answer on May 26, 2026 at 10:50 pm

    Because tests of that nature could lead to unexpected bugs in programs, thus they favored requiring boolean expressions to be explicit (as did Java), instead of performing an implicit conversion to bool.

    This is also the same reason why you cannot use an int as a boolean expression in C#. Since the only valid boolean expressions are expressions that evaluate directly to bool, this keeps unexpected errors from being introduced in the code, such as the old C gotcha:

    if (x = 5)
    { 
       // always true
    }
    

    So, in short, it was not included in order to favor readability and explicitness. Yes, it does come at a slight cost in brevity, but the gains in reduction of unexpected bugs more than make up for the cost of hainvg to add != null inside the parenthesis…

    (You can, of course, create an implicit conversion of a custom type to bool, as a workaround, but you can’t globally apply that to any object type)

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

Sidebar

Related Questions

If there are several methods in the test class, I found that the order
I have this function that takes a pointer of an array (in order to
I'm trying to test an Order entity method called AddItem and I'm trying to
I am writing a junit test in order to (surprisingly) test a part of
I've been looking at ways people test their apps in order decide where to
I'm trying to use fixtures to add more complex test data in order to
So i am trying to do this Order.find :all, :conditions => org = 'test
See the following Mock Test by using Spring/Spring-MVC public class OrderTest { // SimpleFormController
In IE7, my order sample button #itmSampl isn't vertically aligned with the .add-to-cart button
So i have a small integration test that houses 5 tests in total. Running

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.