0
如何使下面的DoScrape方法添加到外部CompanyInfo變量,然後在button1_Click的循環中訪問該列表以寫入文本文件?C#全局類 - 從方法中添加並從另一箇中讀取
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
});
}
}
resharper再次襲擊? – paul 2013-02-27 14:13:12
@paul - 有什麼reshalper做這件事? – 2013-02-27 14:13:47
抱歉,必須隱藏原始代碼,但DoScrape是遞歸方法。這是否改變了答案? – 2013-02-27 14:14:06