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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:54:38+00:00 2026-05-29T04:54:38+00:00

I have the following OR operator, now currently if the c is null the

  • 0

I have the following OR operator, now currently if the c is null the Error view will be returned and no null exception will be raised on the second check (!c.ManagedBy…); but this will only happen if the compiler perform the (c==null) check before the (!c.Ismanaged..) check.

Book c = elearningrepository.GetBook(id);

if ((c == null) || (!c.IsManagedBy(User.Identity.Name)))
{
    return View("Error");
}

so can I guarantee that the compiler will always perform the c==null check first or it is better to split the above check into two separate If statements to explicitly enforce the sequence.
BR

  • 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-29T04:54:39+00:00Added an answer on May 29, 2026 at 4:54 am

    || does short-circuit and will evaluate exactly as you have described. There’s no need to separate the statements.

    From MSDN:

    The conditional-OR operator (||) performs a logical-OR of its bool
    operands. If the first operand evaluates to true, the second operand
    isn’t evaluated. If the first operand evaluates to false, the second
    operator determines whether the OR expression as a whole evaluates to
    true or false.

    Edited for the most recent MSDN article (2010).

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

Sidebar

Related Questions

I have the following SQL query: select expr1, operator, expr2, count(*) as c from
I have the following code: template <typename T> LuaCall& operator>>(T) { BOOST_STATIC_ASSERT(sizeof(T) == 0);
I have the following code: template <class T> struct pointer { operator pointer<const T>()
I have the following code: class Sales_item { public: int ii; Sales_item& operator=(const Sales_item
I have the following classes with an implicit cast operator defined: class A {
I have the following object literal: var a = {a:1,b:2} now I want another
I've two tables which have following columns: Now I want have a SQL query
I have my GET Method working and mapping my returned objects correctly. Now I
I have two tables like the following hotels ------ hotelID hotelName Second table operators
I am reviewing C++ casts operator and I have the following doubt: for polymorphic

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.