I using the codes below to print out the reverse name of a user input but I couldn't understand why the Console.WriteLine
call prints out "Your reverse name is: System.Char[]"? If I just type Console.WriteLine(reverseName)
, it print out the reverse name correctly. What is different in this code? Couldn't understand why the usage a placeholder would give different output? Isn't it refer to the same information in reverseName
?
static void Main(string[] args)
{
var name = "Alice";
char[] reverseName = new char[name.Length];
for (var i = name.Length - 1; i > -1; i--)
{
reverseName[i] = name[name.Length - 1 - i];
}
Console.WriteLine(reverseName); // "ecilA"
Console.WriteLine("Your reverse name is: {0} ", reverseName);
// "Your reverse name is: System.Char[]"
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…