Good afternoon, please help me, there is a text file called "From" with the following content:

10 1 6 8 6 1 2

You need to read all the numbers and put them in the "mas" array so that you can output to the console in this way:

for (int i = 0; i < massiv; i++) Console.WriteLine("в массиве [{0}] храниться число {1}", i , mas[i]); 

To output on the console:

 в массиве [0] храниться число 10 в массиве [1] храниться число 1 

etc.

massiv is the length of the array.

Thank you in advance.

Closed due to the fact that the essence of the question is incomprehensible to the participants by Grundy , pavel , Denis , aleksandr barakin , Bald 18 Aug '16 at 10:34 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

2 answers 2

 using (StreamReader sr = new StreamReader(@"From.txt")) { string line; while ((line = sr.ReadLine()) != null) { string[] text = line.Split(' '); for (int i = 0; i < text.Length; i++) { Console.WriteLine("в массиве [{0}] хранится число {1}", i, text[i]); } } } 
  • Thank you all so much nito I have never worked with it. Ilya Vityuk
 // string text = "10 1 6 8 6 1 2"; // для чтения строки из файла string text = File.ReadAllText(@"C:\путь_к_файлу\from.txt"); string[] myArray = text.Split(); for (int i = 0; i < myArray.Length; i++) Console.WriteLine("в массиве [{0}] храниться число {1}", i, myArray[i]); 
  • And what if the numbers will be random? + it is not clear how much? @Ruslan_k - Ilya Vityuk
  • @ Ilyavityuk: The same? - VladD
  • @Ruslan_K Thank you too - Ilya Vityuk