首页 > 其他 > 详细

扩展方法

时间:2014-06-10 12:54:09      阅读:320      评论:0      收藏:0      [点我收藏+]

利用扩展方法,实现参数验证。

bubuko.com,布布扣
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace 扩展方法
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             string name = Console.ReadLine();
14             name.Required();
15             Console.WriteLine("你好," + name);
16             Console.ReadKey();
17         }
18     }
19 
20     public static class Validate
21     {
22         public static void Required(this string data)
23         {
24             if (string.IsNullOrEmpty(data))
25             {
26                 //Console.WriteLine("姓名不能为空");
27                 throw new ArgumentException("参数不能为空。");                
28             }
29         }
30     }
31 }
bubuko.com,布布扣

 

扩展方法,布布扣,bubuko.com

扩展方法

原文:http://www.cnblogs.com/David-Huang/p/3778852.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!