-1

Hi I'm making a simple web scraping solution that gets several titles of different articles and I want to save all the extracted titles (strings) into an array from a foreach loop.

foreach (var item in doc.DocumentNode.SelectNodes("//h2[@class='entry__title']"))
{
     Console.WriteLine(item.InnerText);
}

Is there a specific way to? I been looking in the documents but seems like I just can't make it work..

Frawsty
  • 54
  • 7
theo
  • 11
  • 2
  • Does this answer your question? [Adding values to a C# array](https://stackoverflow.com/questions/202813/adding-values-to-a-c-sharp-array) – G Wimpassinger Oct 17 '21 at 15:17

1 Answers1

0

If you want to just replicate what you have mentioned, use linq

var arraydata = doc.DocumentNode.SelectNodes("//h2[@class='entry__title']")).Select(t=>t.InnerText).ToArray();
MaartenDev
  • 5,631
  • 5
  • 21
  • 33
Mayur Ekbote
  • 1,700
  • 1
  • 11
  • 14