在处理流水号时,一般需要把对应的整数转换为相应位数的字符串。
/// <summary> /// 把整数转换为指定位数的字符串 /// </summary> /// <param name="slen">位数(这里允许最大32位)</param> /// <param name="maxSN">整数</param> /// <returns></returns> public string setSN(int slen, int maxSN) { string sn = "00000000000000000000000000000000"; sn = sn.Substring(0, slen - (maxSN + 1).ToString().Length) + (maxSN + 1).ToString(); if (maxSN.ToString().Length >= slen) { sn = maxSN.ToString(); } return sn; }