New course! Every coder should learn Generative AI!
Try a free lesson0
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); " ????
4 Answers
+ 2
You have to write :
Console.WriteLine(m + " " + n);
Or
Console.WriteLine(n + " " + m);
+ 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___
0
TY but
This format will work:
Console.WriteLine(n,m); -----> 1st string and then int
and the other one wont why??
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.