Reputation: 27
is there a way to have a matrix that stores an int and a boolean at the same time?
Imagine having a matrix: matrix[x, y]
Now, is it somehow possible to do something like this?
matrix[2, 1] = 5, true
matrix[1, 5] = 2, false
The matrix simply stores an int and a boolean value at the same time.
Upvotes: 0
Views: 362
Reputation: 11322
C# 7.0 introduced a simple syntax for tuples to store multiple values in one matrix element:
var matrix = new (int, bool)[10, 10];
matrix[2, 1] = (5, true);
matrix[1, 5] = (2, false);
The example creates a 2D array of 10 times 10 tuples.
Here, (int, bool)
defines tuples which consist of an int
and a bool
value.
It would be simpler to use two matrices in parallel, one for the integers and one for the bool values.
Upvotes: 1