Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the printf in C# [duplicate]

Tags:

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

like image 677
user2387220 Avatar asked Jan 26 '15 17:01

user2387220


People also ask

What is printf () and scanf in C?

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'.

What is scanf () in C?

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.

What is %d printf?

%d tells printf that the corresponding argument is to be treated as an integer value; the type of the corresponding argument must be int .

What is printf example?

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.


1 Answers

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}"); 
like image 193
Bauss Avatar answered Sep 24 '22 16:09

Bauss