Why does this work...
int[] mySadIntArray = new int[] { 2, 3, 4, 8, 9 };
JSONArray mySadJSONArray = new JSONArray();
foreach (int i in mySadIntArray)
mySadJSONArray.Add(i);
// Add Functions
public override void Add(JSONNode aItem)
{
var tmp = new JSONArray();
tmp.Add(aItem);
Set(tmp);
}
public override void Add(string aKey, JSONNode aItem)
{
var tmp = new JSONObject();
tmp.Add(aKey, aItem);
Set(tmp);
}
But not this?
playerJSON.Add("C", mySadIntArray.ToJSONArray());
With...
public static JSONArray ToJSONArray<T>(this IEnumerable<T> array) where T : JSONNode
{
JSONArray JSONArray = new JSONArray();
foreach (T node in array)
JSONArray.Add(node);
return JSONArray;
}
Gives me the error:
The type 'int' cannot be used as type parameter 'T' in the generic type or method 'ExtensionMethods.ToJSONArray(IEnumerable)'. There is no boxing conversion from 'int' to 'SimpleJSON.JSONNode'.
If there is not boxing conversion, shouldn't it also break in the "Why does this work..." code?