0

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.

3
  • I think error message is clear. Don't use Array.Find on string[,] Commented Jun 18, 2016 at 21:51
  • Shouldn't it be : Find<string, string> Commented Jun 18, 2016 at 23:58
  • Find<string><string> was a good idea but it didn't work. I thought there would be an easier way than traversing the array and I thought .Find would be it but I guess the syntax is not obvious. Commented Jun 19, 2016 at 1:09

1 Answer 1

1

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=="" ));
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much. I ended up making an array scan function.

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.