I tried int.parse,
and convert class to convert a string to int.
While I\'m converting. I\'m losing the 0 in the beginning which i don\'t want.
// For our requirement that new ID's should be of same length as old ID's.
string strID = "002017";
int number = int.Parse(strID);
string newID = (++number).ToString("D" + strID.Length);
you cant, but if you need to cast it to int and keep the zeros you can create a copy of it and then cast it to int, then you will have two versions of it one as int and one as string.
Although this is a old thread, but this can also help:
// convert to big integer
var bigIntBits = BigInteger.Parse(intNumber);
int indexOfOne = intNumber.IndexOf('1');
string backToString = new string('0', indexOfOne) + bigIntBits.ToString();
you cannot. you will have to maintain the value as a string if you want it to remain that way.
If you want to do something like always print your number with 5 places, it goes like
myNumber.ToString().PadLeft(5, '0');
Int values cannot have leading zeros