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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:52:33+00:00 2026-06-05T14:52:33+00:00

I have a problem in using list in the loops and I appreciate if

  • 0

I have a problem in using list in the loops and I appreciate if any of you guys can help me.
I want to create a list and populating it from array (named in my code: sarray) with the values bigger than -999. But the problem is when the values are less than -999, the code dumps the previous items of the list and the size instead of being 40, is 27 (as if new list list is created)!

  List<double> nums = new List<double>();
        for (int i = 0; i < 50; i++)
        {
            if (sarray[i] > -999)
            {
                nums.Add(sarray[i]);

            }
        }

these are the values:

[31411.0857 31411.0902 31411.0847 31411.0858 31411.0859 31411.0479 31411.0649 31411.0895 31411.0944 31411.0207 31411.0683 31411.0717 31411.075 31411.0825 -999 -999 -999 -999 -999 -999 -999 -999 -999 -999 31411.0156 31411.0718 31411.0719 31411.0884 31411.0885 31411.0936 31411.0896 31411.0897 31411.0537 31411.066 31411.0661 31411.0556 31411.0701 31411.0731 31411.0952 31411.0716 31411.0776 31411.0803 31411.091 31411.0911 31411.0919 31411.0919 31411.0919 31411.0919 31411.0919 31411.0919 ]

  • 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-05T14:52:35+00:00Added an answer on June 5, 2026 at 2:52 pm

    The generic list takes an enumerable in one of its overloaded constructors, and you can use the Linq Where extension method to constrain the items to add:

    var nums = new List<double>(sarray.Where(d => d > -999));
    

    You state that -999 represents a “null” value for you, in that case you could change the Where to not assume the valid values are greater than -999:

    var nums = new List<double>(sarray.Where(d => d != -999));
    

    I believe this style expresses the intent more clearly than crafting your own loops.

    As an aside, double.NaN might be a more obvious representation of an invalid value.


    But the problem is when the values are less than -999

    This is because you are only checking where values are greater than -999: if (sarray[i] > -999)

    However, the value dump you provided doesn’t have any items that are less than -999 so this check will suffice – so long as the data set remains the same.

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

Sidebar

Related Questions

I am using Jasper Report 4.5 My problem is I have list of employees
i have problem using LIKE structure in DB2 : for example: select * from
I have a problem using the SSIS. I try to import data from database
Problem: I have file named by their Id from database. And when somebody want
I have a method that loops through a list and creates Links using the
I have problem using arabic font for iOS. All fonts have the same render,
I have problem while using jquery maskedinput with asp.net textbox. I have a check
I have a problem using a local SQL Server CE database with C# and
I have a problem using Linq to NHibernate to load an object and eagerly
I have a problem using JSON and arrays. Here is my code: while($row =

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.