分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 运营维护

.Net高级技术:Linq

发布时间:2023-09-06 02:27责任编辑:彭小芳关键词:暂无标签

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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved