Why does not display the reversed a and b?

static void Main(string[] args) { try { Console.Write("Введите А: "); string a = Console.ReadLine(); Console.Write("Введите Б: "); string b = Console.ReadLine(); string c = b; b = a; a = c; Console.WriteLine("Новое А: ", a); Console.WriteLine("Новое Б: ", b); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); } } 

enter image description here

    2 answers 2

    You are using the wrong overload of the WriteLine method.

    You can output as

     Console.WriteLine("Новое А:" + a); Console.WriteLine("Новое Б:" + b); 

    Or if you want to use the one that you have, then you need so because The first argument is a formatted string similar to the String.Format method.

     Console.WriteLine("Новое А: {0}",a); Console.WriteLine("Новое Б: {0}",b); 

      Of course, does not display! You need concatenation: "Новое А: "+a .

       static void Main(string[] args) { try { Console.Write("Введите А: "); string a = Console.ReadLine(); Console.Write("Введите Б: "); string b = Console.ReadLine(); string c = b; b = a; a = c; Console.WriteLine("Новое А: "+a); Console.WriteLine("Новое Б: "+b); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); } } 

      UPD

      Yes, as you have already answered, you can also apply line formatting: Console.WriteLine("Новое А: {0}",a);

      By the way, two lines of output can be replaced by one. Then it will be easier for you to understand the essence of formatting strings; the essence of concatenation.

      Formatting:

       Console.WriteLine("Новое А: {0}\nНовое Б: {1}",a,b); 

      Concatenation:

       Console.WriteLine("Новое А: "+a+"\nНовое Б: "+b);