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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:16:38+00:00 2026-06-08T13:16:38+00:00

I have a requirement where I need to filter out the null values from

  • 0

I have a requirement where I need to filter out the null values from a list, only if the null value appears after the first non-null value and before the last non-null value.

Product one = new Product { Name="A" Priority="1" Value=null };
Product two = new Product { Name="A" Priority="2" Value=null };
Product three = new Product { Name="A" Priority="3" Value="10" };
Product four = new Product { Name="A" Priority="4" Value=null };
Product five = new Product { Name="A" Priority="5" Value="20" };
Product six = new Product { Name="A" Priority="6" Value=null };

In the example, I need to first sort the list of products based on their priority and then check the first non-null value (ie., priority 3) and last non-null value (ie, priority 5), then get the list of all products with null values within priority 3 & 5. So, in our example only Product 4 with Priority 4 is the record I am looking for.
I got to the part of actually grouping them by products and sorting them by priority but stuck on how to proceed after that

from p in Products
group p by p.Product into grp
select new
{
   Product = grp.Key
   Values = grp.OrderBy(x => x.Priority)
}

Can someone point me as how to proceed? I am thinking I may to use the indexes to identify all the non-null and iterate through to get min and max Priority values and later query for all records with blank null values within the min/max priority.

  • 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-08T13:16:39+00:00Added an answer on June 8, 2026 at 1:16 pm

    How about this (you can use .Select instead of .SelectMany to get separate groups for each product. .SelectMany combines all the valid result records into a single list):

    Products
        .GroupBy(p => p.Name)
        .SelectMany (grp =>
            grp.OrderBy(p => p.Priority)           // sort by priority
                .SkipWhile(p => p.Value == null)   // skip null entries at beginning
                .Reverse()                         // reverse
                .SkipWhile(p => p.Value == null)   // skip null entries at end
                .Reverse()                         // reverse back to normal
                .Where(p => p.Value == null)       // then find null entries
        );
    

    Demo: http://ideone.com/2dU9L

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

Sidebar

Related Questions

I have a predicate and i need to filter out an attribute. The name
I have a predicate and i need to filter out an attribute. The name
I have a requirement where I need to run an RFC from an ETL
Hi i have a requirement i need your help for it:- I have a
I have the requirement that I need to open a document in Microsoft word
I have a requirement that I need to show my records in a gridview
I have a requirement wherein I need to display on a User form, a
I have a requirement where i need to enter a text in the text
I have a requirement where I need to implement a thumbs up, thumbs down
Rehrasing the question - Question rephrased - I have a requirement where I need

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.