printf uses a formatting string to output directly to the console: anything in the string prefaced with '%' indicates a "placeholder" which will be replaced with a value from the list of variables that follows the format string:
printf("The value is %d!", i);
Will print "The value is 666!" or similar depending on the value in
i
when the statement is executed.
Console.Write and Console.WriteLine work much the same under normal circumstances: you supply a format string and a list of parameters and they are replaced:
Console.WriteLine("The value is {0}!", i);
Will print the same as the printf example (there are other ways to print parameters with Write and WriteLine, but I'll ignore those here).
Unless there is just one parameter, in which case it it printed exactly as it is:
Console.WriteLine("The value is {0}!);
Will print "The value is {0}!"
When you specify an non printable value as the parameter to Write or WriteLine though, things are different. An
int
will print a string representation of the number: "666", as will a double: "666.66", and a byte is also not printable, so you get the numeric value or the byte: "#" will print as "35" because that is the ASCII representation of a '#' character, 'T' as a "84", '2' as "50", '5' as "53", and so on.
See here:
ASCII Table[
^] and the values should be clearer.