为什么的Debug.WriteLine输出一些变量,以我的文字的左边? [英] Why does Debug.Writeline output some variables to the left of my text?
问题描述
我有以下的代码,我想知道为什么从线资产名称输出粘变量,我的文字,而不是右边的左边? ?谁能帮助
这:
System.Diagnostics.Debug .WriteLine(------------ ------------ LoadContent);
System.Diagnostics.Debug.WriteLine(LoadContent:资产名称:{0},theAsset);
System.Diagnostics.Debug.WriteLine(LoadContent:雪碧X偏移:{0},thisSpriteXCentreOffset);
System.Diagnostics.Debug.WriteLine(LoadContent:雪碧Y偏移:{0},thisSpriteYCentreOffset);
输出这个(粗线是意外的):
------------ ------------ LoadContent
飞船:LoadContent:资产名称:{0}
LoadContent:雪碧X偏移:64
LoadContent:雪碧Y偏移:32
块引用>
解决方案我的猜测是,
theAsset
是字符串
,因此你调用的的Debug.WriteLine(字符串,字符串)
而不是的Debug.WriteLine的(字符串,对象[])
。在这种情况下,第二个参数被解释为类别和前置到输出中。
您可以尝试它转换为一个
对象
来调用正确的过载:的Debug.WriteLine(LoadContent:资产名称:{0}, (对象)theAsset);
I have the following code and I want to know why the output from the line 'Asset Name' sticks the variable to the left of my text instead of the right? Can anyone help?
This:
System.Diagnostics.Debug.WriteLine(" ------------ LoadContent ------------"); System.Diagnostics.Debug.WriteLine("LoadContent: Asset Name : {0}", theAsset); System.Diagnostics.Debug.WriteLine("LoadContent: Sprite X Offset : {0}", thisSpriteXCentreOffset); System.Diagnostics.Debug.WriteLine("LoadContent: Sprite Y Offset : {0}", thisSpriteYCentreOffset);
Outputs this (Bold line being the unexpected one):
------------ LoadContent ------------
SpaceShip: LoadContent: Asset Name : {0}
LoadContent: Sprite X Offset : 64
LoadContent: Sprite Y Offset : 32
解决方案My guess is that
theAsset
is astring
, and you're therefore invokingDebug.WriteLine(string, string)
instead ofDebug.WriteLine(string, object[])
. The second argument in this case is interpreted as a "category" and prepended to the output.You might try casting it to an
object
to invoke the correct overload:Debug.WriteLine("LoadContent: Asset Name : {0}", (object)theAsset);
这篇关于为什么的Debug.WriteLine输出一些变量,以我的文字的左边?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!