0

我喜欢这样的语法:

Something something = new Something
{
  Property1 = "property1",
  Property2 = "property2"
}

但在当前项目中,我看到以下内容:

Something something = new Something();
something["Property1"] = "property1";
something["Property2"] = "property2";

我想知道是否有办法重构后者以某种方式接受后者的语法。我试图看看智能感知会提出什么建议,但没有变得更聪明。建议?

4

1 回答 1

0

如果某物是字典,那么

Something something = new Something()
{
    {"Property1", "property1"},
    {"Property2", "property2"}
}
于 2013-05-22T16:11:02.740 回答