0

How to change the values in a matrix C#

Ok. I need to show the values in a specific row of a matrix, but they have to be one column ahead from the original one and the last value has to become the first one of the row. How can I do this ?

31st Oct 2020, 7:08 PM
Valério Brito dos Santos
Valério Brito dos Santos - avatar
2 Réponses
0
Can you give a specific example of numbers in this matrix and the data you'd want to print? If you just want to know how to represent the matrix, an array of arrays, ArrayList, or List of rows or List of columns would be good data types.
3rd Nov 2020, 10:00 AM
Josh Greig
Josh Greig - avatar
0
You can wrap around from the last element to the first element by using a simple 'if' statement or a ternary operator, but for cleaner code you can use the modulus operator (%). matrix[row][(col + 1)%colCount] Note: colCount would be the total number of columns, which is the maximum index + 1.
3rd Nov 2020, 2:50 PM
Brian
Brian - avatar