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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:40:48+00:00 2026-06-15T05:40:48+00:00

I have the following method in my project: public double CalculateDailyProjectMaxPumpSpm(DateTime date, string start

  • 0

I have the following method in my project:

public double CalculateDailyProjectMaxPumpSpm(DateTime date, string start = null, string end = null)
{
    Log("Calculating Daily Pump stroke Max...");

    var spm = new List<double>();

    if (start == null)
    {
        for (var i = 0; i < _pumpOneSpm.Count; i++)
        {
            if (_date[i].Equals(date))
            {
                spm.Add(_pumpOneSpm[i]);
                spm.Add(_pumpTwoSpm[i]);
            }
        }
    }
    else
    {
        for (var i = 0; i < _pumpOneSpm.Count; i++)
        {
            if (_date[i].Equals(date) && 
                DateTime.Compare(_time[i], DateTime.Parse(start)) > 0 && 
                DateTime.Compare(_time[i], DateTime.Parse(end)) < 0)
            {
                spm.Add(_pumpOneSpm[i]);
                spm.Add(_pumpTwoSpm[i]);
            }
        }
    }

    return _dailyProjectMaxSpm = Math.Round(spm.Max(), 2, MidpointRounding.AwayFromZero);
}

I’m trying to make the method look a little less unwieldy. I had tried:

public double CalculateDailyProjectMaxPumpSpm(DateTime date, string start = null, string end = null)
{
    Log("Calculating Daily Pump stroke Max...");

    var spm = start == null ? _pumpOneSpm.Concat(_pumpTwoSpm).Where((t, i) => _date[i].Equals(date)).ToList()
                            : _pumpOneSpm.Concat(_pumpTwoSpm).Where((t, i) => _date[i].Equals(date) && 
                                                                              DateTime.Compare(_time[i], DateTime.Parse(start)) > 0 && 
                                                                              DateTime.Compare(_time[i], DateTime.Parse(end)) < 0).ToList();

    _dailyProjectMaxSpm = Math.Round(spm.Max(), 2, MidpointRounding.AwayFromZero);

    return _dailyProjectMaxSpm;
}

But when I ran the program I got an Index out of range. Must be non-negative and less than the size of the collection. Parameter name: index error. Now, I couldn’t care less what order the elements are added to the new list, just so long as if the conditions are met, they are added. Could anyone help me out with the error? Thanks.

UPDATE

_date is a list of dates pulled from a database, and _time is a list of timestamps pulled from the same database. All variables with the _ is a list pulled from a database. The Count of each list will always be equal to the Count of each other list.

  • 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-15T05:40:49+00:00Added an answer on June 15, 2026 at 5:40 am

    Like sil said, you’re concatenating the two lists, resulting in a list with a larger index range. How about this solution, which uses Enumerable.Range() to produce the indexes, then uses a combined version of your two predicates to filter, and finally flattens the list with SelectMany():

    public double CalculateDailyProjectMaxPumpSpm(DateTime date, string start = null, string end = null)
    {
        Log("Calculating Daily Pump stroke Max...");
    
        var spm = Enumerable
             .Range(0, _pumpOneSpm.Count)
             .Where(x => _date[x].Equals(date) &&
                         (start == null ||
                          (DateTime.Compare(_time[x], DateTime.Parse(start)) > 0 && 
                           DateTime.Compare(_time[x], DateTime.Parse(end)) < 0)))
             .SelectMany(x => new [] { _pumpOneSpm[x], _pumpTwoSpm[x] });
    
        return _dailyProjectMaxSpm = Math.Round(spm.Max(), 2, MidpointRounding.AwayFromZero);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following method: public string Phase(string phase) { return Phase 1; }
I have the following method: public static T ExecuteScalar<T>( string query, SqlConnection connection, params
I have a method A which might look like following: public double A{ if
I have the following setup: testBean.java with a method public String getResult() , which
I have following method in wcf webenabled service Public Person AddPerson(Person p); As of
I have a RPC service with the following method: public List<Serializable> myMethod(TransactionCall call) {...}
I have the following interfaces defined in a base library project: public interface IWorkContext
I have the following code fragment from a project I'm working on: public void
I have the following controller @Controller @RequestMapping(/project/view.html) public class ProjectViewController { private static final
In my project I have the following helper method, which goes through all the

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.