本人決定把工作中經(jīng)常用到的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 ;
????}
}
??
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
