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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:25:53+00:00 2026-06-15T17:25:53+00:00

BACKGROUND: I created a generic TimeSeries<T> class that should implement the IEnumerable<IEnumerable<T>> interface: public

  • 0

BACKGROUND:
I created a generic TimeSeries<T> class that should implement the IEnumerable<IEnumerable<T>> interface:

public interface ITimeSeries<T> : IEnumerable<IEnumerable<T>> 
{
    T[,] DataMatrix { get; }  

    DateTime[] DateTime { get; }

    string[] Variables { get; }
}

public class TimeSeries<T> : ITimeSeries<T>
{
    public IEnumerator<IEnumerable<T>> GetEnumerator()
    {...}

    IEnumerator IEnumerable.GetEnumerator()
    {
        return GetEnumerator();
    }
}

The TimeSeries<T> class is ‘internally’ implemented as a matrix data structure with each column representing a different variable and each row an observation. There is also an additional DateTime[] array that represents the time axis.

As a start I would like to be able to iterate through the TimeSeries<T> variable by variable with a foreach loop and also through all observations for a specific variable (with an inner foreach loop), but the actual reason for the IEnumerable interface implementation is to get all the features provided by LINQ through the IEnumerable interface, provided that I can somehow ensure that the DateTime association of each observation stays intact.

So for the question:
How should I go about to implement the GetEnumerator method to achieve this?

  • 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-15T17:25:53+00:00Added an answer on June 15, 2026 at 5:25 pm

    Simplest way is just to loop through the rows and return the values of each row. I’m assuming you’re storing in row-major order where the first dimension is the row and the second is the column. Just flip r and c below for column-major order:

    public IEnumerator<IEnumerable<T>> GetEnumerator()
    {
        int rows = DataMatrix.GetLength(0);
        int cols = DataMatrix.GetLength(1);
    
         for(int r = 0; r < rows; r++)
         {
            T[] row = new T[cols]();
    
            for(int c = 0; c < cols; c++)
            {
                row[c] = DataMatrix[r,c];
            }
            yield return row;
        }
    }
    

    If you want to avoid making a copy, you could implement it as either a List of Lists or an Array of Arrays (a T[][] instead of a T[,]).

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

Sidebar

Related Questions

I created a background thread that get's data and returns it to the main
I have created a button CSS class that uses background images with different positions
I created functionality in an appwidget that allows a user to change the background
I have a class who - upon instantiation - creates a background thread that
Background: I have created a CRUD web app using a java based RAD tool
Some background I've created a GUI using a combination of a GUIDE built Figure
Some background: I've created a Swing application which uses the Substance LaF (Thanks again,
I created a button with a 9patch image as a background. In the 9patch
Background: In Drupal 7, I have created a form with CCK (aka the Field
I created a MovieClip symbol in flash containing a dynamic TextField and a background.

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.