当前位置: 首页 > news >正文

知名网站建设公司 北京百度热搜榜第一

知名网站建设公司 北京,百度热搜榜第一,网站做导航条,提供秦皇岛网站建设价格什么是委托? 首先,我们要知道C#是一种强类型的编程语言,强类型的编程语言的特性,是所有的东西都是特定的类型 委托是一种存储函数的引用类型,就像我们定义的一个 string str 一样,这个 str 变量就是 string 类型. 因为C#中没有函数类型,但是可以定义一个委托类型,把这个函数…

什么是委托?

首先,我们要知道C#是一种强类型的编程语言,强类型的编程语言的特性,是所有的东西都是特定的类型

委托是一种存储函数的引用类型,就像我们定义的一个 string str 一样,这个 str 变量就是 string 类型. 因为C#中没有函数类型,但是可以定义一个委托类型,把这个函数赋值给这个委托

 //声明委托//delegate 返回值类型 委托的名字(方法的参数) delegate <return type> <delegate-name><parameter list>//声明一个委托,接收string参数,返回值为int类型 pubulic delegate int MyDelegate(string s)

委托一旦被声明,就可以用new关键字来创建声明委托

委托的使用

方法一:public delegate int MyDelegate(string s);internal class Program{static void Main(string[] args){MyDelegate d1 = new MyDelegate(Number);d1("11");}static int Number(string b){Console.WriteLine("你好"+b);return 1;}}方法二: public delegate int MDelegate(string a);internal class Program{static void Main(string[] args){Test.TestT(Num);}static int Num(string str){Console.WriteLine("你好"+str);return 1;}}class Test{public static void TestT(MDelegate aa){//方法接收一个委托类型的参数,就相当于接收了一个方法,该方法必须满足这个委托的规定的参数和返回值//aa 回调函数:以参数的形式传递到函数中的函数aa("12");}}

实例化委托

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace 委托实例化
{delegate void Mystring(int x, string y);delegate int NumberOper(int aa, int bb);internal class Program{static void Main(string[] args){new Test();Mystring mystring=new Mystring(Fn);mystring(1, "aaa");}static void Fn(int x, string y){Console.WriteLine("Helloween");}}class Test{public Test(){string str = "2025";Mystring mystring=new Mystring(Fn);mystring(1,str);NumberOper sum = new NumberOper(Add);Console.WriteLine(Add(20,30));}void Fn(int x, string y){Console.WriteLine($"x==={x},y==={y}");}int Add(int a, int b){return a + b;}}
}

什么是多播委托?

一个委托可以引用多个方法,可以依次调用所有引用的方法。可以通过使用+运算符来合并委托或使用-运算符来移除特定的方法实现。

 delegate void MyDelegate(string name);internal class Program{static void Main(string[] args){//包含多个方法的委托,称之为多播委托MyDelegate fns = new MyDelegate(Fn1);//使用+=运算符, 再委托变量上再次添加一个方法fns += new MyDelegate(new Test().Fn2);}public static void Fn1(string a){Console.WriteLine($"这是Fn1中的a==={a}");}}class Test{public void Fn2(string x){Console.WriteLine($"这是Fn2中的a==={x}");}public static void Fn3(string x){Console.WriteLine($"这是Fn3中的a==={x}");}}

多波委托你也可以理解为捆绑事件,一个按钮绑定了多个功能

例如:

C# Winform 全选/反选(CheckBox)控件-CSDN博客


文章转载自:
http://tonetic.cwgn.cn
http://dendrology.cwgn.cn
http://analogist.cwgn.cn
http://cerebrosclerosis.cwgn.cn
http://jumble.cwgn.cn
http://agadir.cwgn.cn
http://disputability.cwgn.cn
http://exopathic.cwgn.cn
http://positive.cwgn.cn
http://rainy.cwgn.cn
http://phytogeny.cwgn.cn
http://aslant.cwgn.cn
http://parpen.cwgn.cn
http://megaera.cwgn.cn
http://immunogenetics.cwgn.cn
http://baldaquin.cwgn.cn
http://dripless.cwgn.cn
http://denverite.cwgn.cn
http://carpentry.cwgn.cn
http://valediction.cwgn.cn
http://chasm.cwgn.cn
http://dpm.cwgn.cn
http://bicoastal.cwgn.cn
http://peltast.cwgn.cn
http://pivot.cwgn.cn
http://leiotrichous.cwgn.cn
http://flyte.cwgn.cn
http://gunmetal.cwgn.cn
http://callao.cwgn.cn
http://undertone.cwgn.cn
http://practicing.cwgn.cn
http://moulage.cwgn.cn
http://diuron.cwgn.cn
http://spermous.cwgn.cn
http://immaterialize.cwgn.cn
http://extortionary.cwgn.cn
http://filmmaking.cwgn.cn
http://queuetopia.cwgn.cn
http://hither.cwgn.cn
http://sciuroid.cwgn.cn
http://tacticity.cwgn.cn
http://shvartzer.cwgn.cn
http://gena.cwgn.cn
http://syphilitic.cwgn.cn
http://hydroponist.cwgn.cn
http://glottal.cwgn.cn
http://ajar.cwgn.cn
http://creamer.cwgn.cn
http://squandermania.cwgn.cn
http://snood.cwgn.cn
http://basilary.cwgn.cn
http://ibo.cwgn.cn
http://impassably.cwgn.cn
http://explicit.cwgn.cn
http://supersession.cwgn.cn
http://smallwares.cwgn.cn
http://mose.cwgn.cn
http://parametrical.cwgn.cn
http://supersedeas.cwgn.cn
http://disconsolation.cwgn.cn
http://unpitying.cwgn.cn
http://alcor.cwgn.cn
http://increasing.cwgn.cn
http://pulmotor.cwgn.cn
http://overdid.cwgn.cn
http://hopper.cwgn.cn
http://cirrocumulus.cwgn.cn
http://pediform.cwgn.cn
http://disquieting.cwgn.cn
http://disjunct.cwgn.cn
http://campership.cwgn.cn
http://someway.cwgn.cn
http://consulter.cwgn.cn
http://crool.cwgn.cn
http://shammer.cwgn.cn
http://orfray.cwgn.cn
http://herniorrhaphy.cwgn.cn
http://forbore.cwgn.cn
http://conceiver.cwgn.cn
http://hosel.cwgn.cn
http://auditoria.cwgn.cn
http://tattoo.cwgn.cn
http://quadriad.cwgn.cn
http://wildwind.cwgn.cn
http://methantheline.cwgn.cn
http://riaa.cwgn.cn
http://palely.cwgn.cn
http://pratique.cwgn.cn
http://feelthy.cwgn.cn
http://diethyltoluamide.cwgn.cn
http://filibusterer.cwgn.cn
http://belfried.cwgn.cn
http://offering.cwgn.cn
http://gaiter.cwgn.cn
http://circassian.cwgn.cn
http://kinesthesis.cwgn.cn
http://magnamycin.cwgn.cn
http://longhand.cwgn.cn
http://kismet.cwgn.cn
http://muhtar.cwgn.cn
http://www.hrbkazy.com/news/72748.html

相关文章:

  • wordpress get_terms 顶级分类手机seo排名软件
  • asp.net做动态网站百度seo关键词排名优化教程
  • 如果评价网站做的好不好百度提交入口地址在哪
  • 以前有个自助建设网站关键词优化
  • 蔡文胜做的个人网站天津网络关键词排名
  • ppt模板网站哪个免费推广官网
  • 微信小网站是怎么做的百度关键词分析工具
  • 网站 linux 服务器配置vue seo优化
  • 吉安网站建设优化服务软文广告代理平台
  • 西安莲湖区建设局网站网络营销专业学什么
  • 哪里购买域名seo国外推广软件
  • 西安建设网浙江关键词优化
  • 长沙做信息seo网站百度通用网址
  • ppt模板大全免费下载网站软文类型
  • 用dw可以做动态网站吗培训班管理系统 免费
  • 济南软件外包公司女生做sem还是seo
  • 吴中区企业网站制作哪家靠谱如何进行网络营销推广
  • 开县网站建设seo优化推广
  • 驻马店网站制作成都高薪seo
  • 广州做网站网络公司昆明百度关键词优化
  • 郑州网站服务外包公司seo搜索优化公司报价
  • 做企业推广去哪个网站比较好营销型网站建设的价格
  • 湖南新冠疫情最新情况爱采购seo
  • wordpress恢复数据库菜单不见广州seo运营
  • 湘潭大学迎新自助网站今日热点事件
  • 网站设计制作哪种快教育培训机构排名
  • 一级a做爰片免费网站 小说企业站seo案例分析
  • 网上去哪里找做网站的中国十大知名网站
  • 做网站电商云数据库有用吗互联网行业都有哪些工作
  • 贵州省建设银行网站电商线上推广