我尝试使用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
}
使用字典
[&#34; Barcode&#34;,&#34;&#34;]
我不确定这里适合做什么。我确实想要字符串,因为我需要在我的程序中稍后使用它进行比较。