Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. int[,] arrayBidimensional = new int[3, 3]
  2. {
  3. { 1, 2, 3 },
  4. { 4, 5, 6 },
  5. { 7, 8, 9 }
  6. };
  7.  
  8. using System;
  9.  
  10. class MainClass {
  11. public static void Main (string[] args) {
  12. int[,] arrayBidimensional = new int[3, 3]
  13. {
  14. { 1, 2, 3 },
  15. { 4, 5, 6 },
  16. { 7, 8, 9 }
  17. };
  18.  
  19. var novoArray = new int[arrayBidimensional.GetLength(0) * arrayBidimensional.GetLength(1)];
  20.  
  21. int colunas = arrayBidimensional.GetLength(1);
  22. for(int i = 0; i < arrayBidimensional.GetLength(0); i++) {
  23. for(int j = 0; j < colunas; j++) {
  24. var indice = colunas * i + j;
  25. novoArray[indice] = arrayBidimensional[i, j];
  26.  
  27. Console.WriteLine($"{indice} = {novoArray[indice]}");
  28. }
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement