2014-10-02 119 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

回答