本人决定把工作中经常用到的C#编程技巧记录在博客中,以备查阅。
所有的代码均在 .NET2.0 下测试通过。引用命名空间如下:


1

2

3

4

5

(1)、删除List<T>中元素相同的项。


1

2



3



4

5

6

7



8

9



10

11

12

13

14

(2)、验证手机号


public static void VerifyMobilephone()
{
Regex rgxChinaUnicom = new Regex( @" ^(130|131|132|133|153|155|156)[0-9]{8}$ " );
Regex rgxChinaMobile = new Regex( @" ^(134|135|136|137|138|139|150|157|158|159)[0-9]{8}$ " );
Console.WriteLine( " please input Mobilephone Number: " );
string a = Console.ReadLine();
if (rgxChinaMobile.IsMatch(a))
{
Console.WriteLine( " It is ChinaMobile Number! " );
}
else if (rgxChinaUnicom.IsMatch(a))
{
Console.WriteLine( " It is ChinaUnicom Number! " );
}
else
{
Console.WriteLine( " you input a Error Number! " );
}
}
(3)、在Access中插入一条记录后得到最新的自动编号


1

2



3

4

5

6

7

8

9

10

11

(4)、验证字符串中是否包含中文和中文字符


protected static bool HaveChinese( string str)
{
if (Regex.IsMatch(str, @" [\u4E00-\u9FA5|,。?:;‘’!“”……——、()【】《》¥]+ " ))
{
return true ;
}
else
{
return false ;
}
}
更多文章、技术交流、商务合作、联系博主
微信扫码或搜索:z360901061

微信扫一扫加我为好友
QQ号联系: 360901061
您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。
【本文对您有帮助就好】元
