我正在使用XNA库为C#开发一个简单的游戏.在下面的代码片段中,我得到了
收集被修改; 枚举操作可能无法执行.
第二个foreach循环顶部的错误.在我(相对有限的)C#体验中,这在尝试在循环期间修改底层集合时会发生.但是,据我所知,我没有以任何方式修改enemy_positions集合.此代码中的所有集合都属于此类型List<Vector2>.
这里发生了什么?
//defines collision behaviour when enemy is hit
int be_no = 0;
List<Vector2> tmp_bullets = bullet_i_position;
List<Vector2> tmp_enemy = enemy_positions;
foreach (Vector2 bullet in bullet_i_position)
{
//get bullet collision box
Rectangle bullet_col = new Rectangle(Convert.ToInt32(bullet.X - 12), Convert.ToInt32(bullet.Y - 12), 25, 26);
int en_no = 0;
foreach (Vector2 enemy in enemy_positions)
{
//get enemy collsion box
en_box = new Rectangle(Convert.ToInt32(enemy.X), Convert.ToInt32(enemy.Y), 75, 75);
if (temp_r.Intersects(en_box))
{
//remove all colliding elements
tmp_enemy.RemoveAt(en_no);
tmp_bullets.RemoveAt(be_no);
bullet_direction.RemoveAt(be_no);
} …Run Code Online (Sandbox Code Playgroud) 我有以下js片段:
cat_images = $(".category-description").next().find("img");
cat_images.each(function () {
url = $(this).parent().attr("href");
id = url.split("id=");
id = id[1];
url = "cat_url.php?i="+id;
this_image = this;
$.get (url, function (data) {
$(this_image).attr("src", data);
});
});
Run Code Online (Sandbox Code Playgroud)
目前,ajax.get部分仅更新每个循环迭代的最后一个元素.我认为这与ajax与循环交互不良有关,因为this在ajax函数中使用会使其完全失败.
无论如何,在等待ajax在Jquery中完成时,有没有延迟循环?(宁愿不混合普通的js)
我有这个正则表达式模式:
r = New Regex("^((\"(?:[^\"]|\"\")*\"|[^,]*)(,(\"(?:[^\"]|\"\")*\"|[^,]*))*)$");
Run Code Online (Sandbox Code Playgroud)
这导致此错误: "CS1002: ; expected"
我看不出是什么导致了这一点.