扩展方法的使用
2016-11-24 22:08
127 查看
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;
}
}
}
在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();
}
}
}
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();
}
}
}
相关文章推荐
- C#3.0 中使用扩展方法来扩展接口
- NetTiers学习笔记08---Entity层的扩展和EntityDataSource的使用方法
- 使用扩展方法和静态门面类实现伪领域对象
- AjaxControlToolKit ----ConfirmButtonExtender (确认提示框按钮扩展)的简单使用方法
- 标准文件对话框的扩展使用方法
- C# 3.0新特性初步研究 Part2:使用扩展方法
- AjaxControlToolKit ----CalendarExtender(日历扩展控件)的简单使用方法
- c#3.0 中使用扩展方法来扩展接口
- vs2008中让基于.net 2.0的应用程序也可以使用扩展方法
- AjaxControlToolKit DropDownExtender(下拉扩展控件)使用方法
- fix-ie5.js扩展在IE5下不能使用的几个方法
- 使用74系列芯片作为I/O并行扩展的方法以及总线驱动芯片的使用方法
- .net 3.0+关于实现IEnumerable的类型的扩展方法的使用一
- [翻译] ASP.NET MVC Tip #1 - 使用扩展方法创建新的HTML Helper
- C#3.0 中使用扩展方法来扩展接口
- C# 3.0新特性初步研究 Part2:使用扩展方法_C#教程
- C#3.0 中使用扩展方法来扩展接口
- C# 3.0新特性初步研究 Part2:使用扩展方法_C#教程
- 在.net 2.0/3.0程序中使用扩展方法
- AjaxControlToolKit ----DropDownExtender(下拉扩展控件) 的简单使用方法