Good afternoon, I ask me to help, there is a text file called “From” with such content:
10 1 6 8 6 1 2
You need to read all the numbers and put into the “MAS” array so that you can withdraw to the console in this way:
for (int i = 0; i & lt; massiv; i ++)
Console.WriteLine ("In an array [{0}] is stored {1}", i, mas [i]);
To bring on the console:
in the array [0] is stored number 10
In the array [1] is kept number 1
, etc.
Massiv is the length of the array.
Thanks in advance.
Answer 1, Authority 100%
using (StreamReader SR = New StreamReader (@ "from.txt"))
{
String Line;
While ((Line = Sr.ReadLine ())! = NULL)
{
String [] Text = Line.split ('');
for (int i = 0; i & lt; text.length; i ++)
{
Console.WriteLine ("In the array [{0}] is stored {1}", i, text [i]);
}
}
}
Answer 2, Authority 150%
// String Text = "10 1 6 8 6 1 2";
// To read the string from the file
String Text = File.ReadallText (@ "C: \ Path_file \ FROM.TXT");
String [] Myarray = Text.Split ();
for (int i = 0; i & lt; ryarray.length; i ++)
Console.Writeline ("In the array [{0}] number {1}", i, myarray [i]);