0

This is a follow up question to Design issues and implementing Enumerable.AsEnumerable<FarPoint.Win.Spread.Row>

I have casted my farpoint row to a 2 d object array like this:

object[,] nthRow = fpSpread2.ActiveSheet.GetArray(e.Row, e.Column, 1, FarPointSpread1.ActiveSheet.ColumnCount);

I try to cast this to string so that i can apply Linq but i get the following error at runtime:

IEnumerator<string> narry = (IEnumerator<string>)nthRow.GetEnumerator();

Unable to cast object of type 'ArrayEnumerator' to type 'System.Collections.Generic.IEnumerator`1[System.String]'.

How can i resolve this problem?

Community
  • 1
  • 1
Expert Novice
  • 1,943
  • 4
  • 22
  • 47

1 Answers1

2

Even for multidimensional arrays you can call Cast<T> on it.

using System.Linq;
...
nthRow.Cast<string>().GetEnumerator()    // returns IEnumerator<string>

But each element in the array should actually be type string. If you want to do formatting like ToString(), you can first cast them into object and then call Select<T>.

Gildor
  • 2,484
  • 23
  • 35
  • I just need a single dimensional array from 0th index how can i get that? – Expert Novice Dec 02 '13 at 11:02
  • @Lohit that cannot be easily done in C# given a multidimensional array. You have to copy the array elements. But, if you only want one row, **why don't you specify the row number when you call `fpSpread2.ActiveSheet.GetArray`**? – Gildor Dec 02 '13 at 11:09