小编Jam*_*mes的帖子

C# - 在foreach中更改字典键值对的值

我有这个代码在游戏的每一帧运行:

    foreach (var repeaterAction in conditionTimes.Keys)
    {
        if (repeaterAction.Condition() == true)
        {
            if (conditionTimes[repeaterAction] == TimeSpan.Zero)
            {
                repeaterAction.Action();
            }
            else if (conditionTimes[repeaterAction] >= repeaterAction.InitialLapse)
            {
                repeaterAction.Action();
                conditionTimes[repeaterAction] -= repeaterAction.ActionInterval;
            }
            conditionTimes[repeaterAction] += gameTime.ElapsedGameTime;
        }
        else
        {
            conditionTimes[repeaterAction] = TimeSpan.Zero;
        }
    }
Run Code Online (Sandbox Code Playgroud)

这给了我以下错误:

收集被修改; 枚举操作可能无法执行.

有没有办法修改foreach循环中键值对中的值,而不是每帧都复制Dictionary?

c# collections foreach dictionary enumeration

9
推荐指数
2
解决办法
2万
查看次数

翻转顶点数组

我有一组构成二维多边形的位置顶点。

        Vector2[] _chassisConcaveVertices =
        {
            new Vector2(5.122f, 0.572f),
            new Vector2(3.518f, 0.572f),
            new Vector2(3.458f, 0.169f),
            new Vector2(2.553f, 0.169f),
            new Vector2(2.013f, 0.414f),
            new Vector2(0.992f, 0.769f),
            new Vector2(0.992f, 1.363f),
            new Vector2(5.122f, 1.363f),
        };
Run Code Online (Sandbox Code Playgroud)

我可以使用什么算法来修改位置以便翻转生成的多边形?我需要水平和垂直翻转多边形。

c# algorithm flip vertex

2
推荐指数
1
解决办法
1912
查看次数

标签 统计

c# ×2

algorithm ×1

collections ×1

dictionary ×1

enumeration ×1

flip ×1

foreach ×1

vertex ×1