what is the printf in C# [duplicate]

牧云@^-^@ 提交于 2019-12-30 08:01:49

问题


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


回答1:


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}");


来源:https://stackoverflow.com/questions/28155317/what-is-the-printf-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!