Equivalent to VB format in C #

What will be the equivalent code for Format(iCryptedByte, "000") (VB.NET) in C #?

+7
c # vb.net-to-c #
source share
6 answers

Try:

 iCryptedByte.ToString("D3"); 
0
source share
 String.Format(format, iCryptedByte); // where format like {0:D2} 

See MSDN 1 , 2 , 3

+10
source share

Another very useful site for formatting C # strings: http://blog.stevex.net/string-formatting-in-csharp/

Instead of {0:D3} you can also use a null placeholder, for example. {0:000} will be filled with zeros to a minimum length of three.

+2
source share

Given this VB code:

 Strings.Format(iCryptedByte, format) 

Replace with this C # code:

 var csformat = "{0:" + format + "}"; String.Format(csformat, iCryptedByte); 
+1
source share
0
source share
 Microsoft.VisualBasic.Strings.Format(iCryptedByte, "000"); 

You need to add a link to the Microsoft.VisualBasic assembly.

0
source share

All Articles