klasscho

Untitled

Nov 25th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. static int[,] GetArrayFromFile(string fileName)
  2. {
  3. if (!File.Exists(fileName))
  4. return null;
  5. string[] lines = File.ReadAllLines(fileName);
  6. int rowCount = lines.Length;
  7. if (rowCount == 0)
  8. return null;
  9. int colCount = lines[0].Split().Length;
  10. if (colCount == 0)
  11. return null;
  12. int[,] array = new int[rowCount, colCount];
  13. for (int i = 0; i < rowCount; i++)
  14. {
  15. string[] line = lines[i].Split();
  16. for (int j = 0; j < colCount; j++)
  17. {
  18. array[i, j] = int.Parse(line[j]);
  19. }
  20. }
  21. return array;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment