Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing variables to console

Tags:

c#

Can someone explain difference in this 2 codes.

Console.WriteLine("Our total"+ total);

and

Console.WriteLine("Our total {0}", total);

Which of code is more or less correctly than other?

like image 546
Natty Avatar asked Oct 30 '25 08:10

Natty


1 Answers

In this line

Console.WriteLine("Our total"+ total);

will always contact after left side of + sign is finish.

In this line

Console.WriteLine("Our total {0}", total);

will print where it's position is putted.

Like

Console.WriteLine("{0} is our total ", total);

This'll print first in the string.

if total is 10

Output :

10 is our total.

Both is correct but with different way of printing.

like image 175
Anik Islam Abhi Avatar answered Nov 01 '25 21:11

Anik Islam Abhi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!