The best way to do this is:
txtCarros.Text = string.Join("\t", novoCarro.mostraModelo(), novoCarro.mostraPlaca(), novoCarro.mostraKm(), "\n");
Manually concatenating string generates several allocations and this, in addition to being slow, creates pressure on the garbage collector. This case does not do much damage, but if it increases the number of items it gets worse exponentially.
I put the tabs that is the question asks, and the line break only at the end.
Simplified:
public class Program { public static void Main() => System.Console.WriteLine(string.Join("\t", "modelo", "placa", "km", "\n")); }
See running on .NET Fiddle . And no Coding Ground . Also I placed GitHub for future reference .
Join()
documentation.
But if you're doing everything in the same expression you can simplify the syntax that the compiler will transform to Concat()
for you, and it fits even better:
txtCarros.Text = novoCarro.mostraModelo() + "\t" + novoCarro.mostraPlaca() + "\t" novoCarro.mostraKm() + "\n";
For a few items it does not make sense to use StringBuilder
, especially when the final size is unknown.
Another alternative would be:
txtCarros.Text = $"{novoCarro.mostraModelo()}\t{novoCarro.mostraPlaca()}\t {novoCarro.mostraKm()}\n";