扩展方法的使用
来源:互联网 发布:邦家博士骗局揭秘 知乎 编辑:程序博客网 时间:2024/04/28 01:22
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Test扩展方法
{
static class StringExtend
{
public static bool IsEmal(this string s)//在static类中,在static方法中的第一个参数上加一个 this,就是对这个参数的类型的扩展。
{
if (s.Contains("@"))
{
return true;
}
else
return false;
}
public static string AddString(this string s,string str)//this必须加在第一个参数上面才能形成对第一个参数类型的扩展。
{
return s + str;
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Test扩展方法
{
static class StringExtend
{
public static bool IsEmal(this string s)//在static类中,在static方法中的第一个参数上加一个 this,就是对这个参数的类型的扩展。
{
if (s.Contains("@"))
{
return true;
}
else
return false;
}
public static string AddString(this string s,string str)//this必须加在第一个参数上面才能形成对第一个参数类型的扩展。
{
return s + str;
}
}
}
在main函数中调用
namespace Test扩展方法
{
class Program
{
static void Main(string[] args)
{
string s = "123@qq.com";
Console.WriteLine(s.IsEmal());
Console.WriteLine(s.AddString("zzzz"));//带参数的扩展方法
Console.ReadKey();
}
}
}
0 0
- 扩展方法的使用
- 扩展方法的使用
- c#扩展方法的使用
- C# 扩展方法的使用
- C#中扩展类和扩展方法的使用
- 使用本地方法扩展你的应用程序
- 关于使用扩展方法的警告
- C# this扩展方法的使用
- unity中扩展方法的简单使用
- string扩展方法使用
- 扩展方法使用
- 使用扩展方法创建新的HTML Helper
- 使用native方法扩展Java程序的功能
- Firefox 3.6.X下使用Google Notebook扩展的方法
- 使用native方法扩展Java程序的功能详解
- 使用C#的扩展方法替代For循环
- 使用 Eclipse TPTP 测试 Web 应用的方法与扩展
- cocos2d-x使用extension扩展包的方法
- 【Codeforces 738F】 Financiers Game【记忆化DP】
- leetcode_436. Find Right Interval 找距离最近的右间隔,对结构体对象的列表排序
- IceBox divergent
- Presents
- 计算器
- 扩展方法的使用
- 排序
- XCode8导航栏反色异常简单解决
- WiFi 网络也可以这么玩
- Java中的异常大集合
- java类集 map-使用
- Android启动页停留2秒跳转到主页或这引导页的最好好实现
- 环信
- XML基础知识总结