C# String.Format() technique with Example: Here, we will figure out how to print content (less or zero) with the numbers in C#?
To print the content (less or zero) with the numbers, we can utilize String.Format() strategy for String class in C#.
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Demo for zero and negative integer number:");
Console.WriteLine(String.Format("{0:#;minus #}" , 256));
Console.WriteLine(String.Format("{0:#;minus #}" , -256));
Console.WriteLine(String.Format("{0:#;minus #;zero}" , 0));
Console.WriteLine();
}
}
}
Output:
Demo for zero and negative integer number:
256
minus 256
zero
In the above program, we printed the content “short 256” instead of – 256 and print “zero” instead of 0.