Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int[,] GetArrayFromFile(string fileName)
- {
- if (!File.Exists(fileName))
- return null;
- string[] lines = File.ReadAllLines(fileName);
- int rowCount = lines.Length;
- if (rowCount == 0)
- return null;
- int colCount = lines[0].Split().Length;
- if (colCount == 0)
- return null;
- int[,] array = new int[rowCount, colCount];
- for (int i = 0; i < rowCount; i++)
- {
- string[] line = lines[i].Split();
- for (int j = 0; j < colCount; j++)
- {
- array[i, j] = int.Parse(line[j]);
- }
- }
- return array;
- }
Advertisement
Add Comment
Please, Sign In to add comment