I’m using a class that has an indexer defined and would like to get the data out of it and into a simple array. Is there a better way than looping through the indexer?
The indexer:
public class MyIndexer
{
public int Foo { get; }
public int GetSize{ get; } //size of data vector
public float this[int idx] { get; set; }
}
Something like this would be nice:
float[] data = indexer.GetData();
Note that I can’t change MyIndexer.
Since you can get the number of elements, you can create an extension method:
You could also just use a for loop: