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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:40:50+00:00 2026-05-24T02:40:50+00:00

i wanted to try the following code: //all arrays are List<T> type. if (m.terms[0]

  • 0

i wanted to try the following code:

//all arrays are List<T> type.
if (m.terms[0] != null && m.terms[0].labels != null && m.terms[0].labels[0].title == "Part-of-speech")
{
    result = true; 
}

but it occured runtime error occasionly in following situation

i. m.terms == null

ii. m.terms != null, but m.terms[0] does not intialized.

iii. m.terms != null, and m.terms[0] has been exist but
m.terms[0].label does not initialized.

…

so i did modify it to like this:

if (m.terms[0] != null)
{
    if (m.terms[0].labels != null)
    {
        if (m.terms[0].labels[0].title == "Part-of-speech") { result = true; }
    }
}

is it the best way?

  • 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-24T02:40:51+00:00Added an answer on May 24, 2026 at 2:40 am

    && is a short circuiting operator, so the first way you wrote it and the second way will be functionally equivalent.

    if (a && b && c)
    {
        // work 
    }
    

    b will only be evaluated if a returns true. (Same goes for c).

    In your code, checking m.terms[0].labels will not be a problem because you would have short-circuited out of the expression if m.terms[0] had been null.

    To completely cover yourself, you’d want to possibly add checks for m and m.terms, however.

    m != null && m.terms != null && m.terms.Count > 0 && m.terms[0] != null ...
    

    As it evaluates from left to right, it will break on the first condition that doesn’t pass and the rest will go unchecked.

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

Sidebar

Related Questions

Consider the following code: try { int *i = NULL; i[100] = 20; catch
I wanted to use the following code from here: How can I save all
I have the following code: def causes_exception(lamb): try: lamb() return False except: return True
I wanted to try a little design by contract in my latest C# application
I have wanted to try GAE since launch, but coming from ASP .NET and
so I wanted to try my first CLR project in Visual C++. So I
After I've seen this PDC session I wanted to try to learn a bit
Inspired by this question , I wanted to try my hand at the latest
I am working on some scraping app, i wanted to try to get it
I have a quick little application and wanted to give a try to develop

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.