IL_0066: call System.Collections.Generic.IEnumerable`1<System.Linq.IGrouping`2<!!1,!!0>> System.Linq.Enumerable::GroupBy<System.Int32,System.Int32>(System.Collections.Generic.IEnumerable`1<!!0>,System.Func`2<!!0,!!1>) 

打包了pc版本, 運行時出現錯誤, 查了下 ILRuntime 官方, 總覺得 Linq 似乎沒法用 RegisterFunctionDelegate 解決, 查了網上說的的確只能自己改寫功能

private List<int> getUniqNumList(List<int> nums)
{
    List<int> ret = new List<int>();

    Dictionary<int, int> groupCounts = new Dictionary<int, int>();
    foreach (int num in nums)
    {
        if (!groupCounts.TryGetValue(num, out int oNum))
            groupCounts[num] = 1;
        else
            groupCounts[num]++;
    }

    foreach(int k in groupCounts.Keys)
    {
        if (groupCounts[k] == 1)
            ret.Add(k);
    }
    return ret;
}

#if ILRuntime
    List<int> guess_one = this.getUniqNumList(guess_list);
#else
    List<int> guess_one = guess_list.GroupBy(x => x).Where(x => x.Count() == 1).Select(x => x.Key).ToList();
#endif

标签: none

添加新评论