C#生成流水号编码[a-z(不包括i和o) 按0-9 a-z的顺序)]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; namespace ConsoleApplication1
{
public class Program
{
static void Main(string[] args)
{
CustomBaseNumber cbn = new CustomBaseNumber("0123456789abcdefghjklmnpqrstuvwxyz");
cbn.CustomBase = "";
for (int i = ; i < ; i++)
{
Console.WriteLine(cbn.CustomBase.PadLeft(, ''));
cbn.DecBase++;
}
Console.ReadKey();
}
}
class CustomBaseNumber
{
private string _chars;
public CustomBaseNumber(string chars)
{
_chars = chars;
}
public string CustomBase
{
get
{
string value = "";
int decvalue = DecBase;
int n = ;
if (decvalue == ) return new string(new char[] { _chars[] });
while (decvalue > )
{
n = decvalue % _chars.Length;
value = _chars[n] + value;
decvalue = decvalue / _chars.Length;
}
return value;
}
set
{
int n = ;
Func<char, int> getnum = (x) => { for (int i = ; i < _chars.Length; i++) if (x == _chars[i]) return i; return ; };
for (int i = ; i < value.Length; i++)
{
n += Convert.ToInt32(Math.Pow((double)_chars.Length, (double)(value.Length - i - )) * getnum(value[i]));
}
DecBase = n;
}
}
public int DecBase
{
get;
set;
}
}
}
上一篇:【ASP.NET 进阶】定时执行任务


下一篇:Linux中磁盘mbr分区——实践篇