2

I am reading in data from an Excel sheet so I have this code to get the region I want;

Excel.Range range = (Excel.Range)worksheet.get_Range("A9", "AO" + (worksheet.UsedRange.Rows.Count).ToString());
System.Array rangeCells = (System.Array)range.Cells.Value;

So my Data is x long and 41 cells wide so my array looks like;

rangeCells[1,1] through to rangeCells[1,41] is line 1
rangeCells[2,1] through to rangeCells[2,41] is line 2

and so forth until the end.

Does anyone know of a LINQ way to get each line into an object?

17
  • 2
    Why do you need LINQ? Commented Jul 2, 2013 at 21:49
  • 3
    What would the object look like? Commented Jul 2, 2013 at 21:51
  • 1
    @I4V Why do you need air to breathe? Commented Jul 2, 2013 at 21:55
  • 4
    @HighCore Don't comment just to comment. Linq is good but not necessary. griegs, Linq wouldn't make your code more efficent. Commented Jul 2, 2013 at 22:02
  • 1
    @griegs Going by RandomWebGuy's links, it seems that multidimensional arrays do, however, implement non-generic IEnumerable. So range.Cells.Value.Cast<whatever>().Select() is also an option. Commented Jul 2, 2013 at 23:00

1 Answer 1

1

I don't believe this is possible because multi-dimensional arrays do not impliment IEnumerable

Discussed more:

Sign up to request clarification or add additional context in comments.

3 Comments

@AbeMiessler Seeing as LINQ-to-Objects is a set of extension methods over IEnumerable(T), the fact that only onedimensional arrays implement that interface would be a sticking point.
@KevinBabcock If by "ways around that" you mean doing something to flatten the array, then you're not really working with a 2D array anymore. (I admit this is splitting hairs, but the ambiguity alone means this answer isn't wrong per se, if not particularly helpful.)
@millimoose agreed (removed my comment)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.