Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Implement GetEnumerator method for class that implements IEnumerable<IEnumerable<T>>
    text
    copied!<p><strong>BACKGROUND:</strong> I created a generic <code>TimeSeries&lt;T&gt;</code> class that should implement the <code>IEnumerable&lt;IEnumerable&lt;T&gt;&gt;</code> interface:</p> <pre><code>public interface ITimeSeries&lt;T&gt; : IEnumerable&lt;IEnumerable&lt;T&gt;&gt; { T[,] DataMatrix { get; } DateTime[] DateTime { get; } string[] Variables { get; } } public class TimeSeries&lt;T&gt; : ITimeSeries&lt;T&gt; { public IEnumerator&lt;IEnumerable&lt;T&gt;&gt; GetEnumerator() {...} IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } </code></pre> <p>The <code>TimeSeries&lt;T&gt;</code> 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 <code>DateTime[]</code> array that represents the time axis.</p> <p>As a start I would like to be able to iterate through the <code>TimeSeries&lt;T&gt;</code> variable by variable with a <code>foreach</code> loop and also through all observations for a specific variable (with an inner <code>foreach</code> loop), but the actual reason for the IEnumerable interface implementation is to get all the features provided by LINQ through the <code>IEnumerable</code> interface, provided that I can somehow ensure that the DateTime association of each observation stays intact.</p> <p><strong>So for the question:</strong> How should I go about to implement the <code>GetEnumerator</code> method to achieve this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload