110,571
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// 获取性别
/// </summary>
/// <param name="cardId"></param>
/// <returns></returns>
public virtual bool GetSex(string cardId)
{
if (RegexCard(cardId))
{
string sexCode = string.Empty;
if (cardId.Length == 15)
{
sexCode = cardId.Substring(14, 1);
}
else
{
//18位身份证取第17位数
sexCode = cardId.Substring(16, 1);
}
int sexNum = int.Parse(sexCode);
return GetSex(sexNum);
}
else
{
throw new Exception("未通过身份验证!");
}
}
private bool GetSex(int sexNum)
{
if (sexNum % 2 == 1)
{
return true;
}
else
{
return false;
}
}
string id="500223198809234421";
string birthday=id.SubString(6,8);
if(int.Parse(id.SubString(15,16))%2==0)
{
MessageBox.Show("女")
}
else
{
MessageBox.Show("男")
}