本文介绍了不能修改返回值,因为它不是一个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按值罢工再次通过!!

Pass by Value strikes again!!

player.Vector.X += player.Speed * (float)gameTime.ElapsedGameTime.TotalSeconds;



不起作用。

does not work.

Vector2 v = player.Vector;
v.X -= player.Speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
player.Vector = v;



修复了这个问题。

fixes this problem.

这是这里解释:

回答得非常好解释和工作得很好,但它已4年,因为它被张贴。 我的问题是,既然它已经4年了,有没有更好的办法,现在解决这个问题?

The answer was very well explained and works just fine, but it has been 4 years since it was posted. My question is, since its been 4 years, is there a better way to fix this problem now?

我对100的这种行我需要修复,并希望能有一些快捷的现在。

I have about 100 lines of this I need to fix, and was hoping there was some sort of shortcut by now.

推荐答案

有可能永远不会成为一个快捷方式这个,因为它是值类型和引用类型之间的根本区别的一个特征。

There is probably never going to be a "shortcut" for this since it's a feature of the fundamental difference between value types and reference types.

这篇关于不能修改返回值,因为它不是一个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-30 00:53