问题
What will be the equivalent code for Format(iCryptedByte, "000")
(VB.NET) in C# ?
回答1:
Try:
iCryptedByte.ToString("D3");
回答2:
String.Format(format, iCryptedByte); // where format like {0:D2}
See MSDN 1, 2, 3
回答3:
Another very useful site for C# string formatting: http://blog.stevex.net/string-formatting-in-csharp/
Instead of {0:D3}
you can also use the zero placeholder, e.g. {0:000}
will pad with zeros to minimum length of three.
回答4:
Given this VB code:
Strings.Format(iCryptedByte, format)
Replace with this C# code:
var csformat = "{0:" + format + "}";
String.Format(csformat, iCryptedByte);
回答5:
see String.Format
回答6:
Microsoft.VisualBasic.Strings.Format(iCryptedByte, "000");
You'll need to add a reference to the Microsoft.VisualBasic assembly.
来源:https://stackoverflow.com/questions/3296645/equivalent-of-format-of-vb-in-c-sharp