A
A
Alexander2020-08-03 16:45:51
C++ / C#
Alexander, 2020-08-03 16:45:51

Displaying multiple values ​​to the console at once does not work. Where is the mistake?

string name = "Tom";
            int age = 34;
            double height = 1.7;
            bool isEmployment = false;
            
            Console.WriteLine($"Name: {0}  Age:{1}  Height: {2}  Employment: {3},", name, age, height, isEmployment);


It outputs to the console:
Name: 0 Age:1 Height: 2 Employment: 3,

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
yuopi, 2020-08-03
@AlexandrG44

if you write in this format, then you need to erase the $.
if you want to write through the format with $, then instead of 0,1,2,3 substitute variable names inside parentheses.
Option 1:
Console.WriteLine("Name: {0}", name);
Option 2:
Console.WriteLine($"Name: {name}");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question