C#控制台writeline中断字符串并执行错误输出

C#控制台writeline中断字符串并执行错误输出,c#,string,console,formatting,C#,String,Console,Formatting,我只有一个名为string属性的基本类CNode。我只想在控制台中编写它,一切都很好。但当我在string中使用+时,它中断了输出 Console.WriteLine(node.name); 给定输出:word0 此外: string name=node.name; Console.WriteLine(名称); 过于给定的输出:word0 但是: Console.WriteLine(node.Name+“:”); 给定输出::ord0 怎么了? 我也试过: string name = no

我只有一个名为string属性的基本类CNode。我只想在控制台中编写它,一切都很好。但当我在string中使用+时,它中断了输出

Console.WriteLine(node.name);
给定输出:
word0
此外:

string name=node.name;
Console.WriteLine(名称);
过于给定的输出:
word0
但是:

Console.WriteLine(node.Name+“:”);
给定输出:
:ord0

怎么了? 我也试过:

string name = node.Name + ":";
Console.WriteLine(name);
而且也是给我的:
:ord0

注意:

string name=“:”+node.name;
Console.WriteLine(名称);
给我
:word0
输出

如果有帮助,节点对象类代码:

公共类CNode
{
公共字符串名称{get;set;}
}

请帮助,我希望得到
word0:
output

我想写的字符串是
“\r”
,所以如果我需要正常的输出,我只需要做
node.Name=node.Name.Replace(“\r”,”)

试试这个,也许它会帮助你:

string name = node.Name
Console.WriteLine(string.Format("{0} :", name));

你能给我看看吗?目前,我们不知道
word0
来自哪里。你确定是w、o、r、d和0这5个字符吗?你确定里面没有隐藏的字符吗?您可以通过打印
node.Name.Length
.hm lenght为7来检查这一点。如果名称以不可见的回车(\r)终止,但将光标返回到行的开头,则会出现这种情况。hm.i写入:
node.Name=node.Name.Replace(“\r”,”)已修复,请参见?现在循环遍历字符串的每个字符,并通过将其转换为
int
,打印出其int值,以便我们准确地知道它们是哪些字符。执行如下操作:
foreach(node.Name中的字符c){Console.WriteLine((int)c);}