I would like to know how you can fill the elements of the matrix using a certain function that generates numbers in a given range. In C ++, this code looks like this:

double func(int, int) { return rand() % 12; } Matrix::Matrix(int row, int col, double (*func)(int, int)) { ... ... for (int i = 0; i < this->row; i++) { for (int j = 0; j < this->col; j++) { this->arr[i * this->col + j] = func(i, j); } } } 

How to implement similar logic in C #?

  • is this exactly C #? Tag is not confused? - tym32167
  • Code from C ++, but I need to know how to implement a similar constructor in C # - Mecherok
  • Usually, the following question immediately arises for such tasks - have you even tried to solve the problem yourself? What exactly did not work. For example, do you know how cycles are written in C #? Or do you need to do everything from scratch? - AK
  • I thought of doing it with the help of delegates, but I don’t understand how a little, so I ask. I just need to set an example with similar implementations, then I'll figure it out myself. - Mecherok
  • 3
    there is this type of Func<int, int,double> , so you need to pass it to the constructor - tym32167

0