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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:05:28+00:00 2026-06-06T18:05:28+00:00

I have a Item[] _items array of items, where some of the items may

  • 0

I have a Item[] _items array of items, where some of the items may be null. I wish to check if the array contains at least one non-null item.

My current implementations seems a little complicated:

    internal bool IsEmtpy { get { return (!(this.NotEmpty)); } }
    private bool IsNotEmpty { get { return ( this.Items.Any(t => t != null));} }

So my question is: Is there a simpler way to check if a typed array of reference objects contains at least one non null object?

  • 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-06-06T18:05:30+00:00Added an answer on June 6, 2026 at 6:05 pm

    There is no complexity in your implementation. Basically, the only way to check whether there are non-null values in the array is to look through all values until you will reach non-null value or the end of the array.

    The following code is easier to understand though:

    internal bool IsEmtpy { get { return this.Items.All(t => t == null); } }
    private bool IsNotEmpty { get { return this.Items.Any(t => t != null); } }
    

    And it is probably better to extend IEnumerable as follows:

    public static class Extensions {
    
        public static bool ContainsOnlyEmpty<TSource>(this IEnumerable<TSource> source) {
            return source.All(t => t == null);
        }
    
        public static bool ContainsNonEmpty<TSource>(this IEnumerable<TSource> source) {
            return source.Any(t => t != null);
        }
    
    }
    

    and use it like this: bool nonEmpty = this.Items.ContainsNonEmpty();

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

Sidebar

Related Questions

We have an item cull that retrieves items and their appropriate data from one
I have a menu item which has children menu items. When one of the
I have the following code: foreach (ListItem item in check.Items) { if (item.Selected) {
I have an array that is populated using some xpath; so the items in
I have an array of tags per item like so: item1 = ['new', 'expensive']
I have an accordion that binds data for each item from an array. I
I have an array built from the URL of a webpage. If an item
I have product item webpages located in /product/items/*.html?id=12345&ref=54321 and I would like the webpages
We have some XAML which may seem odd but apparently is needed for defining
I have a method that takes a condition and item, from an array of

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.