我有一个方法:
public void MyMethod(params KeyValuePair<string, string>[] properties);
我像这样调用:
MyMethod(
new KeyValuePair("Name","Jack"),
new KeyValuePair("City", "New York"),
new KeyValuePair("Gender", "Male"),
);
我更喜欢更漂亮的语法来调用该方法,类似于:
MyMethod({"Name","Jack"}, {"City","New York"}, {"Gender","Male"});
我最接近的方法是使用更改方法签名以接受字典作为方法参数并调用:
MyMethod(new Dictionary<string,string>()
{
{"Name", "Jack"},
{"City", "New York"},
{"Gender", "Male"},
};
还有其他选择吗?