0

I am in an environment that contains a RollingWindow class where RollingWindow<T> can be a collection of any type/object.

I would like to create a C# method to convert a RollingWindow<T> into a List<T>.

Essentially I'd use it in the following manner:

List<int> intList = new List<int>();
List<Record> = recordList = new List<Record>();
RollingWindow<int> intWindow = new RollingWindow<int>(20); //20 elements long
RollingWindow<Record> = recordWindow = new RollingWindow<Record>(10); //10 elements long

ConvertWindowToList(intList, intWindow); // will populate intList with 20 elements in intWindow
ConvertWindowToList(intList, intWindow); // will populate recordList with 10 elements in recordWindow   

Any thoughts on how I would do this in c#?

Irshad
  • 3,071
  • 5
  • 30
  • 51
alkamyst
  • 15
  • 2

2 Answers2

1

Based on the assumption that RollingWindow<T> implements IEnumerable<T> then;

List<int> intList = intWindow.ToList();
List<Record> recordList = recordWindow.ToList();

will work

Irshad
  • 3,071
  • 5
  • 30
  • 51
-1

I assume that the RollingWindow<T> is derived from IEnumerable<T>.

So this could be possible:

var enumerableFromWin = (IEnumerable<int>) intWindow;
intList = new List<int>(enumerableFromWin);

var enumRecFromWin = (IEnumerable<Record>) recordWindow;
recordList = new List<Record>(enumRecFromWin);
Irshad
  • 3,071
  • 5
  • 30
  • 51