如何将下面的 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
});
}
}