2014-10-02 121 views
0

我試圖枚舉轉換爲使用LINQ枚舉到字典LINQ

一個解釋這是我到目前爲止有:試圖施放鍵時

// returns a dictionary populated with the relevant keys 
public Dictionary<string, string> StartNewEntry() 
{ 
    return Enum.GetNames(typeof(TableDictionary)).ToDictionary(Key => 
         (string)Enum.Parse(typeof(TableDictionary), Key), value => ""); 
} 

它給我的問題。

Unable to cast object of type 'InventoryImportExportLibrary.TableDictionary' to type 'System.String'. 

我在尋找這樣的:

public enum TableDictionary 
{ 
    Barcode = 0, 
    FullName = 1, 
    Location = 2, 
    Notes = 3, 
    Category = 4, 
    Timestamp = 5, 
    Description = 6 
} 

藉助字典,多數民衆贊成

[ 「條形碼」, 「」]

我不知道什麼適合在這裏所做的。我確實需要字符串,因爲我需要稍後在我的程序中使用它進行比較。

+0

如果你只想要字符串?例如,如果你能解釋你想要的結果與我給出的前一個答案相比,這將有所幫助 - 例如,一個枚舉的例子以及預期的字典條目將非常有用。 – 2014-10-02 16:40:29

+0

到目前爲止,你已經說過你寫了一些代碼,並且出現了一些錯誤。你的具體問題是什麼? – 2014-10-02 16:42:34

+0

如何正確設置它?我不明白類型。 – visc 2014-10-02 17:03:22

回答