我有一个这样的结构体:
public struct MapTile
{
public int bgAnimation;
public int bgFrame;
}
但是,当我使用 foreach 循环来更改动画帧时,我无法这样做...
下面是代码:
foreach (KeyValuePair<string, MapTile> tile in tilesData)
{
if (tilesData[tile.Key].bgFrame >= tilesData[tile.Key].bgAnimation)
{
tilesData[tile.Key].bgFrame = 0;
}
else
{
tilesData[tile.Key].bgFrame++;
}
}
它给我编译错误:
Error 1 Cannot modify the return value of 'System.Collections.Generic.Dictionary<string,Warudo.MapTile>.this[string]' because it is not a variable
Error 2 Cannot modify the return value of 'System.Collections.Generic.Dictionary<string,Warudo.MapTile>.this[string]' because it is not a variable
为什么我无法更改字典中结构体内的值?