什么是这段代码的输出?

时间:2010-07-07 19:31:11

标签: c#

 object nullobject = null;
 object myobject = new myobject();
 console.writeline("nullobject="+nullobject+"myobject="+myobject);

1 个答案:

答案 0 :(得分:3)

它(不管怎样,对我而言)打印

nullobject=myobject=System.Object

(将= new myobject();行更改为= new object();并更正其他拼写错误。)

我不知道的事情(以及我很难发布这个的原因)是CSharp在连接时将空字符串对象视为空字符串。关于它,在这个页面的中间有一个注释。 http://msdn.microsoft.com/en-us/library/ms228504.aspx

object nullobject = null;
object myobject = new object();
Console.WriteLine(nullobject + "");         //ok, prints empty line
Console.WriteLine(nullobject.ToString());   //this will blow up
Console.WriteLine("nullobject=" + nullobject + "myobject=" + myobject); //ok, prints what's above.