2014-09-03 73 views
0

我正在編寫一個C#組件,它從輸入參數收集信息並將收集的信息返回到如下字典中:Dictionary。當前方法簽名如下所示:什麼是將特定參數傳遞給方法的最佳方式

public Dictionary<string, object> GenerateAliquotLabel(EAliquoteLabelOptions fieldsToAdd, AliquoteLabelGeneratorParameters parameters) 

參數參數包含從中返回信息的所有來源。我返回的字典中的鍵目前是在內部生成的。

問題是,現在我想指定字典中的鍵作爲參數返回,我不知道任何優雅的方法來做到這一點。

+0

嘗試使用模型 – 2014-09-03 09:26:15

回答

1

如果我理解正確,您的選擇是params。

public Dictionary<string, object> GenerateAliquotLabel(params string[] parameters); 

然後你可以使用類似的String.Format(),例如該方法:

var output = Generator.GenerateAliquotLabel("BlueLabel", "RedLabel", "SmallLabel"); 
相關問題