Missy
Missy

Reputation: 1368

C# Two Dimensional Array and Array.Find - Cannot Convert Error

I have a two dimensional array declared. It has two columns - filename and batch. I initialize it empty.

string[,] a_Reports = new string[,] { { "", "" } };

I have some code that resizes it and populates it. Everything is a string value. When I go to look up an element in the array like so:

int value1 = Array.Find<string>(a_Reports, element=>element.Equals(newFileName));

I get the error:

CS1503  Argument 1: cannot convert from 'string[*,*]' to 'string[]' 

I've tried it every which way and nothing works. Please help me!!! I've spent hours on it already.

Upvotes: 0

Views: 186

Answers (1)

andrei.ciprian
andrei.ciprian

Reputation: 3025

Array.Find is only for one-dimensional arrays. (MSDN)

Check out this answer on 'How do I search a multi-dimensional array?'

Produce a similar extension method, like in my example on rextester.

Or use a jagged array instead of a two-dimensional one and a combination of foreach and find, like:

string[][] jagged = ...
Array.ForEach(jagged, array=>Array.Find(array, x=>x=="" ));

Upvotes: 1

Related Questions