0

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.

1 Answer 1

1

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.

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

1 Comment

wow, thank you so much, that's exactly what I needed!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.