自写扩展方法
2015-08-16 21:25
381 查看
有时候我们需要一个方法,但是.net没有提供,我们需要自己写个扩展方法
直接调用
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CsTest { static class kuozhan { public static string se(this string d) { return d.Remove(0,2); } public static string isou(this int ds) { if (ds%2==0) { return "是个偶数"; } else { return "不是偶数"; } } } }
直接调用
class Program { static void Main(string[] args) { string str = "Hello World!"; str.se(); int b = 67; b.isou(); } }
相关文章推荐
- Mysql事务
- ubuntu 设置root 密码
- 设计模式——原型模式
- Android-网络提交数据get和post的两种方式
- seci-log 1.09 发布 日志分析增加了多个报表和功能点
- 常量指针与指针常量
- 实现多线程的两种方式
- gdb之初识
- 【C/C++学院】0828-数组与指针/内存分配/数据结构数组接口与封装
- CSS Alignment:元素对齐问题
- Android视图绘制流程完全解析,带你一步步深入了解View(二)
- MFC修改菜单
- 【JavaScript】AJax
- 102 Binary Tree Level Order Traversal
- POJ2007--Scrambled Polygon
- c++从零开始学起(关于迭代器的使用)
- hdu 4983 Goffi and GCD(欧拉函数)
- NOIP2010 引水入城
- 求最小的k个数
- 倒排索引