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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:08:50+00:00 2026-05-31T05:08:50+00:00

I have a List of MyObject as below: public MyObject(reqVal, reqTime) { _value =

  • 0

I have a List of MyObject as below:

public MyObject(reqVal, reqTime)
{
    _value = reqVal;
    _time = reqTime;

}

public double Value
{
     get {return _value;}
}

public DateTime Time
{
     get {return _time;}
}

var myList = new List<MyObject>();
myList.Add(new MyObject(100, new DateTime(2012, 03, 01, 10, 0, 0));
myList.Add(new MyObject(50, new DateTime(2012, 03, 01, 10, 3, 0));
myList.Add(new MyObject(10, new DateTime(2012, 03, 01, 10, 6, 0));
myList.Add(new MyObject(230, new DateTime(2012, 03, 01, 10, 9, 0));
....

As you can see this list holds the values for a whole day and each value is generated every 3 min. How can I find the following based on the chunk of 15 min:

  1. maxVal
  2. minVal
  3. openVal
  4. closeVal

so if the 1st datetime value is 2012/03/01 10:00
I need to find the 4 above between 10:00 and 10:15 then next set of 4 between 10:15 and 10:30 and so on …

so all these values will be calculated based on their time range
for example 2nd maxVal or openVal will be the maxVal and openVal between 10:15 and 10:30

any help would be much appreciated,

Thanks.

  • 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-31T05:08:50+00:00Added an answer on May 31, 2026 at 5:08 am

    You could try to group the list by which 15-minute interval it’s in. Here’s a somewhat quick-and-dirty example (I’ve changed some of your values to present better test cases, and TimeData is the same as MyObject):

    List<TimeData> myList = new List<TimeData>();
    myList.Add(new TimeData(100, new DateTime(2012, 03, 01, 10, 0, 0)));
    myList.Add(new TimeData(50, new DateTime(2012, 03, 01, 10, 3, 0)));
    myList.Add(new TimeData(10, new DateTime(2012, 03, 01, 10, 35, 0)));
    myList.Add(new TimeData(230, new DateTime(2012, 03, 01, 10, 46, 0)));
    
    var grouped = myList.GroupBy(t => t.Time.Day.ToString()
           + "_" + t.Time.Month.ToString()
           + "_" + t.Time.Year.ToString()
           + "_" + t.Time.Hour.ToString() + "_"
           + (t.Time.Minute / 15).ToString())
       .Select(gr => new { TimeSlot = gr.Key, Max = gr.Max(item => item.Value),
             Min = gr.Min(item => item.Value),
             Open = gr.OrderBy(g => g.Time).First().Value,
             Close = gr.OrderBy(g => g.Time).Last().Value });
    

    So what is happening is:

    • Group by the day + month + year + hour + (minute / 15).
      • The (t.Time.Minute / 15) is integer division, which means that any minute value from 0 to 14 will equate to 0, 15 to 29 will be 1, and so on.
    • Convert each group into a new class (I’ve made it anonymous for space’s sake), with each group’s key (the string generated in the GroupBy) and the max, min, first and last values in the group.

    You could probably make this run faster by doing the GroupBy a bit differently (i.e. using a class as the group key instead of building a string for each one).

    UPDATE: I generated myself a better test case for this by adding 10,000 elements to myList with random values for the value and minute. I added a .ToList() on the end of the generation of grouped to make sure lazy evaluation wasn’t a factor. It ran in 34 milliseconds. I tried with 100,000 elements and it ran in 226 milliseconds (as measured by a StopWatch). Looks like performance isn’t a huge issue unless resources are constrained and you’ve got hundreds of thousands of elements in myList.

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

Sidebar

Related Questions

I have list of MyObject that looks like this: public class MyObject{ public int
Suppose you have a list of MyObject like this: public class MyObject { public
I have myObjects = List(of myObject) myObject has Public Property myProperty as string Is
Let's say I have a List<MyObject> , which stores class MyObject { public String
I have a object: public class MyObject { int id; string value; } I
If I have a simple object: class MyObject { public string MyValueProperty { get;
I have a List (Of MyObject) binding to a GridView in the Page_Load event.
I have a list of objects from a django queryset, e.g. my_list = MyObject.objects.filter(variable=something)
I have a list List<MyObject> myList and I am adding items to a list
I have a class: public class MyObject { public string Name; public int Age;

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.