我已经阅读this an this,但这并不符合我的需求。如何将一对动态的键/值传递给函数?
我学习Csharp的,这里是我的第一个功能之一:
public void AskServer(string URL, WWWForm form)
{
WWWForm form = new WWWForm(URL);
form.AddField("step", StateManager.STEP_GET_CONF);
form.AddField("pseudo", this._pseudo);
form.AddField("jeton", this._dernierJeton.ToString());
/*... a bit more out of scope code...*/
}
我愿做一个(更)通用这样的东西:
public void AskServer(string URL, ...)
{
WWWForm form = new WWWForm(URL);
/* do a loop on all parameters following the first one */
for (/*dont know how to write this*/) {
form.AddField(param[i], param[i+1]);
)
}
然后调用函数 - 如何 -
AskServer("http://myweb", "pseudo", this._pseudo, "jeton", this._jeton);
也许如果你有一个更好的写作方式,欢迎你,也许有些人如在JavaScript中:
AskServer("http://myweb", {
"pseudo": this._pseudo,
"jeton": this._jeton
});
我的一个问题是,我需要传递的值可能不是字符串(键总是)。
非常感谢您的详细解释,因为我没有说出来,但是这是那种我需要以及件事:详细的解决方案。 – 2014-11-22 16:51:04