Home »
C#
C# | Printing numbers with text (minus or zero) using String.Format() method
C# | String.Format() method with Example: Here, we are going to learn how to print text (minus or zero) with the numbers in C#?
Submitted by IncludeHelp, on November 01, 2019
To print the text (minus or zero) with the numbers, we can use String.Format() method of 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 text "minus 256" in place of -256 and print "zero" in place of 0.