UnityEngine.WWW.WWW(string,byte [],System.Collections.Hashtable)'已经过时了

时间:2014-06-05 04:13:20

标签: c# unity3d

更新到Unity 4.5后,我收到了一个过时的警告:

  

警告CS0618:UnityEngine.WWW.WWW(string, byte[], System.Collections.Hashtable)' is obsolete:不推荐使用此重载。使用带有Dictionary参数的那个。 (CS0618)(Assembly-CSharp)

代码如下:

public class Request {
    public string url;
    public NetworkDelegate del;
    public WWWForm form;
    public byte[] bytes;
    public Hashtable header;

    // Constructors
    public Request(string url, NetworkDelegate del) {
        this.url = url;
        this.del = del;
    }

    public Request(string url, NetworkDelegate del, WWWForm form) : this(url, del) {
        this.form = form;
    }

    public Request(string url, NetworkDelegate del, byte[] bytes) : this(url, del) {
        this.bytes = bytes;
    }

    public Request(string url, NetworkDelegate del, byte[] bytes, Hashtable header) : this(url, del, bytes) {
        this.header = header;
    }

    public WWW makeWWW() {
        if(header != null) {
            return new WWW(url, bytes, header); // problematic line
        }
        if(bytes != null) {
            return new WWW(url, bytes);
        }
        if(form != null) {
            return new WWW(url, form);
        }
        return new WWW(url);
    }
}

我应该如何换行?

可以找到原始代码here

1 个答案:

答案 0 :(得分:5)

WWW构造函数不再需要Hashtable,而是Dictionary(其通用等价物)

如警告所示:将Hashtable header成员替换为Dictionary<K,V>,K为表格中键的类型,V为值的类型。

编辑:

另见why is Dictionary preferred over hashtable