0

I have and Two dimensional array like this.

[A] [B] [C]
[D] [E] [F]
[G] [H] [I]

And I want a function that receive a string as parameter and return an array int[,] with a position of each Word of that string.

public int[,] GetPosition(string Word)
{
    int[,] coordenadas = new int[1, Word.Length];
    for (int value = 0; value < Word.Length; value++)
    {
        char letra = Word[value];
        for (int i = 0; i < row; i++)
        {
            for (int j = 0; j < col; j++)
            {
                if (array[i, j].Equals(letra.ToString()))
                {
                    coordenadas[0, j] = //??
                }
            }
        }
    }

Then I call that function with a Word like GetPosition("GEI")

It has to return an array {{3,1},{2,2},{3,3}}

How can I build an int[,] with every position?

1
  • Does it have to be an int[,]? you could create a custom class with properties Row and Column of type int, then make a List<T> of type custom class and populate the properties of each object to correspond to the position in your letter array for the given word and .Add them to the List<T> which could be returned Commented Aug 7, 2018 at 18:23

1 Answer 1

3

How can I build an int[,] with every position?

You don't want an int[,], you just want a vector (1-D array) where each value is set of two numbers. You could use a Tuple<int, int> or just a plain int[] or some other structure, depending on how you want to use the data..

So then to set the value in the array, you could do:

int[][] coordenadas= new int[][Word.Length];
...
    coordenadas[value] = new int[] {i, j};

Note that coordenadas does not seem to need to be a 2-D array.

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

1 Comment

Ya, I was gonna mention he could flatten it first, to try and simplify.

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.