首页 > Web开发 > 详细

.Net高级技术:Linq

时间:2018-12-22 17:13:39      阅读:141      评论:0      收藏:0      [点我收藏+]

1.系统类的扩展方法

//帮助类标记为static
public static class StringHelper
{
//扩展的方法也要标记为静态的
public static bool IsEmail(this string str)//this要紧跟扩展的类型
{
bool result = true;
if (!str.Contains("@"))
{
result = false;
}
return result;
}

public static string BoolToString(this bool b)
{
string str = string.Empty;
if (b)
{
str="真";
}
else
{
str = "假";
}
return str;
}

public static string BbQuote(this string str, string pre, string tag)
{
return pre + str + tag;
}

}

 

调用扩展的方法:

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string email = "123@qq.com";
bool b = email.IsEmail();
string msg= b.BoolToString();
MessageBox.Show(msg);
MessageBox.Show(email.BbQuote("_","|"));
}
}

 

.Net高级技术:Linq

原文:https://www.cnblogs.com/francis-ray/p/10161155.html

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