为什么的Debug.WriteLine输出一些变量,以我的文字的左边? [英] Why does Debug.Writeline output some variables to the left of my text?

查看:137
本文介绍了为什么的Debug.WriteLine输出一些变量,以我的文字的左边?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的代码,我想知道为什么从线资产名称输出粘变量,我的文字,而不是右边的左边? ?谁能帮助



这:

  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 a string, and you're therefore invoking Debug.WriteLine(string, string) instead of Debug.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆