【发布时间】:2015-01-20 15:51:02
【问题描述】:
我已经阅读了 this 和 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
});
我的一个问题是我需要传递可能不是字符串的值(键始终是)。
【问题讨论】:
标签: c# unity3d parameter-passing