这是我的代码
public class SEWorkflow
{
public Dictionary<SETabs, bool> tabNVPair { get; set; }
}
public enum SETabs
{
Main,
Attachments,
TechTeamReview,
SecurityTeamReview,
TechTeamImplementation
}
//I am initialising like this...
List<SEWorkflow> result = new List<SEWorkflow>()
{
new SEWorkflow()
{
tabNVPair = new Dictionary<SETabs,bool>()
{
SETabs.Main = true,
SETabs.Attachments = true,
}
}
}
Run Code Online (Sandbox Code Playgroud)
我收到错误 // //Error CS0131 赋值的左侧必须是变量、属性或索引器
我将如何初始化?
你太接近了,你错过了方括号:
List<SEWorkflow> result = new List<SEWorkflow>()
{
new SEWorkflow()
{
tabNVPair = new Dictionary<SETabs,bool>()
{
[SETabs.Main] = true,
[SETabs.Attachments] = true,
}
}
};
Run Code Online (Sandbox Code Playgroud)
或者您可以使用花括号,如下所示:
tabNVPair = new Dictionary<SETabs,bool>()
{
{ SETabs.Main, true },
{ SETabs.Attachments, true },
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
74 次 |
| 最近记录: |