Console.WriteLine different ways of writing

in your example, practically not. However, the first case can easily be extended to do

Console.WriteLine("MyVariable value is {0} and myothervar is {1}", i, j);

which could be a little cumbersom with the second approach.


Check out the answer in this thread. In a simple case it doesn't really matter, but there are performance considerations if you are doing this in a large loop or something.


Maybe this will help someone in the future. There is now a 3rd method(Interpolation) and it is the cleanest of them all! They are all just different ways of writing the same thing.

int i = 12;

// Interpolation Method- Req. C# 6 or later [Cleanest]
Console.WriteLine($"MyVariable value is {i}");

// Concatenation Method (from VB days)
Console.WriteLine("MyVariable value is " + i); 

// Format Method (from C days)
Console.WriteLine("MyVariable value is {0}", i);

Tags:

C#