I added a variable of type int and I used it to call something like:
x.ToString("0000");
I changed x to type string and now the above is invalid. Is the only way to format x now:
string.Format("{0:0000}",x);
or is there a short-cut?
I am using StringBuilder to build the string, so does the same apply for AppendFormat?
No real shortcut.
Int32doesn’t have a concept of how many leading zeros the int should have.You’re doing the correct thing by formatting to string. If you’re using that to display stuff, it shouldn’t really be an issue ( you still have
xif you want to perform numeric operations ).AppendFormatworks likestring.Format, but appends to the StringBuilder object it is called on.