I’m having hard time figuring out what collection should I use, either the array Numbers or each line of text in my WebResponce.
Basically, the link in Create method returns 5 numbers. I want to take each line item and place it into array.
I’m having hard time wrapping my head around foreach loop needed to make this work, at least I think I should be using foreach.
int[] Numbers = new int[5];
WebRequest myRequest = WebRequest.Create(
"http://www.random.org/integers/?num=5&min=1&max=56&col=1&base=10&format=plain&rnd=new");
WebResponse myResponce = (WebResponse)myRequest.GetResponse();
Stream myStream = myResponce.GetResponseStream();
StreamReader myReader = new StreamReader(myStream);
Numbers[0] = Convert.ToInt32(myReader.ReadToEnd());
foreach (var item in collection)
{
}
Console.ReadLine();
You don’t need a collection.
Instead, you can read straight out of the StreamReader: