*注意:此方法获得的名字很可能出现生僻字,若要get一个好记/常见的名字,还请另作操作.

以百家姓(444个单姓,60个复姓)作为姓氏,再添加两个随机的中文,You can get a chinese name.

命名不佳等方面,还请谅解.

常见姓氏(80个)在下边(字符数组).

Code:

using System;

namespace CreateChineseName
{
    class Program
    {
        static void Main(string[] args)
        {
            string name = string.Empty;

            //单姓 共444个
            char[] SingleLastName = new char[444] {
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '羿',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '宿', '', '怀', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '寿', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '广', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', '', '', '', '', '', '', '',
                '', '', '', ''
            };

            //复姓 共60个
            string[] DoubleLastName = new string[60] {
                "万俟", "司马", "上官", "欧阳", "夏侯", "诸葛", "闻人", "东方", "赫连", "皇甫",
                "尉迟", "公羊", "澹台", "公冶", "宗政", "濮阳", "淳于", "单于", "太叔", "申屠",
                "公孙", "仲孙", "轩辕", "令狐", "钟离", "宇文", "长孙", "慕容", "鲜于", "闾丘",
                "司徒", "司空", "亓官", "司寇", "子车", "颛孙", "端木", "巫马", "公西", "漆雕",
                "乐正", "壤驷", "公良", "拓跋", "夹谷", "宰父", "谷梁", "段干", "百里", "东郭",
                "南门", "呼延", "羊舌", "微生", "梁丘", "左丘", "东门", "西门", "南宫", "第五"
            };

            //使用随机数在中文随机选取文字
            Random rd = new Random();
            int rdnumber;

            //设置产生的名字数量 默认为1
            int NumberOfNames = 1;
            //基本汉字在unicode编码中位于19968 - 40869
            int ChineseWordsNumber = 40869 - 19968 + 1;
            int FirstChineseWord = 19968;
            while (true)
            {
                for (int i = 0; i < NumberOfNames; ++i)
                {
                    //产生随机数 代表 单姓或复姓 下标(共有444+60=504种姓氏)
                    rdnumber = rd.Next(504);
                    //判断 单姓还是复姓
                    if (rdnumber < 444) name += SingleLastName[rdnumber];
                    else name += DoubleLastName[rdnumber - 444];
                    //添加第一个字
                    rdnumber = rd.Next(ChineseWordsNumber) + FirstChineseWord;
                    name += (char)rdnumber;
                    //添加第二个字
                    rdnumber = rd.Next(ChineseWordsNumber) + FirstChineseWord;
                    name += (char)rdnumber;
                    //显示名字
                    Console.WriteLine(name);
                    //名字重置
                    name = string.Empty;
                }

                //你可以不断回车 以获得新的名字
                Console.ReadLine();
                //清除已显示名字 方便复制
                Console.Clear();
            }
        }
    }
}

常见姓氏:

//常见姓氏有这80个
char[] OftenLastName = new char[80] {
    '','','','','','','','','','',
    '','','','','','','','','','',
    '','','','','','','','','','',
    '','','','','','','','','','',
    '','','','','','','','','','',
    '','','','','','','','','','',
    '','','','','','','','','','',
    '','','','','','','','','',''
};

效果图:

参考:

本文为Dumb原创,请勿抄袭..
12-13 00:46