I want to know what to use in C# to format my output in my console window I tried to use \t but it did not work
I know there is printf in C to format my output
check this image https://s15.postimg.cc/94fstpi2z/Console.png
Printf() and Scanf() are inbuilt library functions in C language that perform formatted input and formatted output functions. These functions are defined and declared in stdio. h header file. The 'f' in printf and scanf stands for 'formatted'.
In C programming language, scanf is a function that stands for Scan Formatted String. It reads data from stdin (standard input stream i.e. usually keyboard) and then writes the result into the given arguments.
%d tells printf that the corresponding argument is to be treated as an integer value; the type of the corresponding argument must be int .
The printf(“:%. 15s:\n”, “Hello, world!”); statement prints the string, but print only 15 characters of the string. In this case the string is shorter than 15, thus the whole string is printed. The printf(“:%15.10s:\n”, “Hello, world!”); statement prints the string, but print 15 characters.
There is no direct "printf" duplication in C#. You can use PInvoke to call it from a C library.
However there is
Console.WriteLine("args1: {0} args2: {1}", value1, value2);
Or
Console.Write("args1: {0} args2: {1}", value1, value2);
Or
Console.WriteLine(string.Format("args1: {0} args2: {1}", value1, value2));
Or
Console.Write(string.Format("args1: {0} args2: {1}", value1, value2));
Or (C#6+ only)
Console.WriteLine($"args1: {value1} args2: {value2}");
Or (C#6+ only)
Console.Write($"args1: {value1} args2: {value2}");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With