以下の DoScrape メソッドを外部の CompanyInfo 変数に追加し、button1_Click のループでそのリストにアクセスしてテキスト ファイルに書き込むにはどうすればよいですか?
namespace Test1
{
public partial class Form1 : Form
{
public class LocationNameAndLink
{
public string Link { get; set; }
public string Name { get; set; }
}
LocationNameAndLink CompanyInfo = new List<LocationNameAndLink>();
private void button1_Click(object sender, EventArgs e)
{
Parallel.ForEach(Brands, item =>
{
string initialSiteName = "http://www.site1.com/" + Brands;
DoScrape(initialSiteName);
});
StreamWriter sw03 = new StreamWriter("websiteCompanyDetails.txt");
foreach (var item in CompanyInfo)
{
sw03.WriteLine("\"" + item.Name + "\",\"" + item.Link + "\"" );
}
}
public static void DoScrape(string PageLink)
{
string SiteLink;
string SiteName;
SourceCode = WorkerClass.getSourceCode(nextPageLink);
SiteLink = SourceCode.Substring(0, 50);
SiteName = SourceCode.Substring(51, 50);
CompanyInfo.Add(new LocationNameAndLink
{
Name = SiteName,
Link = SiteLink
});
}
}