0

i'm going to try explain my question again.

I have a matrix like that

Int32[,] coordinate = new Int32[5, 5];

I'm printing that with thesee codes.

for (int i = 0; i < 5; i++)
        {
            for (int j = 0; j < 5; j++)
            {
                Console.Write(coordinate[i,j] + " ");
            }
            Console.WriteLine();
        }

My question is: When user type "4 2" (there is space between two numbers) That means user selected the coordinate (4,2) (x,y) x = 4 y = 2 I need to set a value to coordinate (4,2) in my matrix. My value is -1. So user typed 4 2 my output should be like that intersect of coordinate

I need to make it dynamically. I hope you can help me. Thank you.

Nezih
  • 381
  • 6
  • 19
  • set: `coordinate[x, y] = value;` and get: `return coordinate[x, y]`. i didn't understand your question property – bansi Jan 22 '16 at 03:30

1 Answers1

0

Try this;

var s ="4 2";
var res = s.Split(' ');
var x = Int32.Parse(res[0]);
var y = Int32.Parse(res[1]);
cordinate[x,y]=-1;

Please not that there is no data validation in this code.

Michał Komorowski
  • 6,198
  • 1
  • 20
  • 24
  • Hi, firstly thank you for your help. But i dont have problem to get value from user. when i check the matris with coordinate[4,2] it doesnt give me the result. Because arrays are working with index. And indexes start with 0 (zero) but my coordinate starts with 1 (one). If you can read my question again i think you'll get what i wanted to explain. Thank you. – Nezih Jan 23 '16 at 23:28
  • As to *"when i check the matris with coordinate[4,2] it doesnt give me the result"*. What does it mean? What result do you receive? – Michał Komorowski Jan 24 '16 at 10:11
  • As to *"And indexes start with 0 (zero) but my coordinate starts with 1 (one)"*. If it is a problem, you can simply substract 1 from coordinates given by a user. – Michał Komorowski Jan 24 '16 at 10:12