製作清單
詞典將是這樣的:
Sidcup - DPC1 Sidcup - DPC 2 布萊克希思 - DPC3 布萊克希思 - DPC4 博克斯雷 - DPC5
其實,我並不完全實現字典如上是個好主意。下面是它的實現:
DataSet ds = EngineBllUtility.GetDPCsForImportFile(connectionString, fileID);
if (ds.Tables.Count > 0)
{
DataTable dtDPCs = EngineBllUtility.GetDPCsForImportFile(connectionString, fileID).Tables[0];
Dictionary<string, string> preliminaryList = new Dictionary<string, string>();
if (dtDPCs.Columns.Contains("DPCNumber") && dtDPCs.Columns.Contains("BranchName"))
foreach (DataRow dataRow in dtDPCs.Rows)
{
preliminaryList.Add(dataRow["BranchName"].ToString(), dataRow["DPCNumber"].ToString());
}
我有以下代碼:(請原諒,最後一行,它只是讓你擁有什麼,我試圖做一個想法)。
foreach (string branch in branchNames)
{
string subfolder = System.IO.Path.Combine(saveLocation, branch);
System.IO.Directory.CreateDirectory(subfolder);
List<string> certificateList = new List<string>();
certificateList.Add(DPCNumber in preliminaryList where Key = branch);
}
在上面的分支是詞典的關鍵。我需要迭代,因爲它需要創建一個新文件夾,然後對我創建的certificateList進行一些操作。
你的字典中每個鍵只有一個值,爲什麼你想從中創建一個列表? – 2012-01-06 10:05:50
您正在循環的每次迭代中以及塊內初始化'certificateList'。它不能在循環之外使用。那是你想要的嗎? – Oded 2012-01-06 10:27:43
@Oded是的,這是所希望的,如果你讀到問題的結尾,你會看到 – ediblecode 2012-01-06 11:07:18