![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
The "#" custom specifier in C#
The "#" custom format specifier works as a digit-placeholder symbol.
If the value to be formatted has a digit in the position where the "#" symbol appears in the format string, then that digit is copied to the resultant string.
We have set a double type here.
double d; d = 4.2;
Now, let us use the “#” custom specifier.
d.ToString("#.##", CultureInfo.InvariantCulture)
Here are other examples.
Example
using System; using System.Globalization; class Demo { static void Main() { double d; d = 4.2; Console.WriteLine(d.ToString("#.##", CultureInfo.InvariantCulture)); Console.WriteLine(String.Format(CultureInfo.InvariantCulture,"{0:#.##}", d)); d = 345; Console.WriteLine(d.ToString("#####")); Console.WriteLine(String.Format("{0:#####}", d)); d = 74567989; Console.WriteLine(d.ToString("[##-##-##-##]")); Console.WriteLine(String.Format("{0:[##-##-##-##]}", d)); } }
Output
4.2 4.2 345 345 [74-56-79-89] [74-56-79-89]
Advertisements