Help with C# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Help with C#

This code: int m = 32; string n = "Mike"; Console.WriteLine(n,m); Why I cant write that like " Console.WriteLine(m,n); " ????

6th Aug 2019, 10:02 AM
Alireza B
Alireza B - avatar
4 Answers
+ 2
You have to write : Console.WriteLine(m + " " + n); Or Console.WriteLine(n + " " + m);
6th Aug 2019, 10:09 AM
Júlia
Júlia - avatar
+ 1
sneeze It does compile because it expect the string define a format to be printed, for example:- Console.WriteLine("{1}-{0}", 1, 2); //prints 2-1 Kindly refer to Microsoft documentation for more info:- https://docs.microsoft.com/en-us/dotnet/api/system.console.writeline?view=netframework-4.8#System_Console_WriteLine_System_String_System_Object___
7th Aug 2019, 1:36 PM
Zephyr Koo
Zephyr Koo - avatar
0
TY but This format will work: Console.WriteLine(n,m); -----> 1st string and then int and the other one wont why??
6th Aug 2019, 10:16 AM
Alireza B
Alireza B - avatar
0
https://code.sololearn.com/c3DDKsu0j4i1/?ref=app Funny it does compile. Although the output is not correct. To print a comma put it between quotes " ". To print a int convert it to a string.
6th Aug 2019, 10:57 AM
sneeze
sneeze - avatar