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

弹幕网站是什么技术做的百度seo公司报价

弹幕网站是什么技术做的,百度seo公司报价,广州站有高铁吗,wordpress在线pdf在C#中,delegate 关键字用于声明委托(delegates),委托是一种类型安全的函数指针,允许你传递方法作为参数或从方法返回方法。有时我们需要将一个函数作为另一个函数的参数,这时就要用到委托(Dele…

在C#中,delegate 关键字用于声明委托(delegates),委托是一种类型安全的函数指针,允许你传递方法作为参数或从方法返回方法。有时我们需要将一个函数作为另一个函数的参数,这时就要用到委托(Delegate)机 制。

delegate void GDelegate<T>(T t);
定义了一个名为 GDelegate 的泛型委托。这个委托接受一个类型为 T 的参数 t,并且不返回任何值(void)。T 是一个类型参数,意味着这个委托可以用于任何类型的方法,只要那个方法有一个参数并且没有返回值。

在C#中,Action 是一个内置的委托(delegate)类型,用于封装没有返回值(即返回类型为 void)的方法。Action 委托有多个重载版本,可以接受不同数量的参数,每个参数可以有不同的类型。
Action 委托的基本定义如下:
public delegate void Action(); // 没有参数  
public delegate void Action<T>(T obj); // 一个参数  
public delegate void Action<T1, T2>(T1 arg1, T2 arg2); // 两个参数  
// ... 以此类推,直到 Action<T1, T2, ..., T16>

在C#中,Func<TResult> 是一个泛型委托,用于封装具有返回值的方法。与 Action 委托不同,Func 委托总是有一个返回值,并且可以接受任意数量的输入参数。在你给出的例子中,Func<String, String> 是一个特定的 Func 委托类型,它接受一个 string 类型的参数并返回一个 string 类型的值。

Func<String,String>func=new Func<String,String>(Method3);
func("我是带返回值的Func委托"); 

Gdelegate类: 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace 泛型委托
{delegate void GDelegate<T>(T t);//定义了一个名为 Gdelegate 的泛型委托。这个委托接受一个类型为 T 的参数 t,并且不返回任何值//T 是一个类型参数,意味着这个委托可以用于任何类型的方法,只要那个方法有一个参数并且没有返回值。internal class Gdelegate//internal 是一个访问修饰符,用于指定一个类型或成员仅在其声明它的程序集中可见{static string result;public static void InvokeDelegate() {GDelegate<string> gdelegate1 = new GDelegate<string>(Method1);//把方法以变量的形式传送,并以方法的形式执行gdelegate1("我是泛型委托1");Action<String>action=new Action<String>(Method1);action("我是泛型委托1-action");//官方版本(不带返回值),效果同
//Action<T>和Func<TResult>这两个内置的委托类型,它们分别在System命名空间中定义,用于处理没有返回值(Action)和带有返回值(Func)的方法。GDelegate<int> gdelegate2= new GDelegate<int>(Method2);gdelegate2(99);//传参intFunc<String,String>func=new Func<String,String>(Method3);result =func("我是带返回值的Func委托");//Func<String, String> 是一个特定的 Func 委托类型,它接受一个 string 类型的参数并返回一个 string 类型的值。}public static void Method1(string str) {Console.WriteLine(str);}public static void Method2(int num){Console.WriteLine("我是泛型委托2:"+num);}public static String Method3(string str){Console.WriteLine(result + "AB");return str+"A";}}
}

  Program类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace 泛型委托
{internal class Program{static void Main(string[] args){Gdelegate.InvokeDelegate();//调用静态方法----类名.方法名string str= Gdelegate.Method3("我是带参的");//str接收的是return str+"A"// Func 委托类型,它接受一个 string--"我是带参的" 类型的参数,并返回一个 stringConsole.WriteLine(str);Console.ReadKey();}}}

启动程序:

AB是在执行:Gdelegate.InvokeDelegate();//调用静态方法----类名.方法名
时执行了: Func<String,String>func=new Func<String,String>(Method3);--->Console.WriteLine(result + "AB");//
而result 此时为null.下一句:result =func("我是带返回值的Func委托:");
 result接收了:"我是带返回值的Func委托:"+"A"
所以才有了执行:string str= Gdelegate.Method3("我是带参的");
时的:我是带返回值的Func委托:AAB
 执行:Console.WriteLine(str);
       我是带参的A

--------------------------------------------

下面我们设计一个马戏表演函数 CircusStart(),它的第一个参数是代表动物表演的函 数,传给它什么样的函数,就进行什么动物的表演。

c#控制台程序:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace delegateAnimalPlay
{internal class Program{//定义委托 delegate void AnimalPlay(string name);//委托声明 AnimalPlaystatic void Main(string[] args){AnimalPlay deleDogPlay = new AnimalPlay(DogPlay); //把函数 DogPlay()转换为 AnimalPlay 型委托CircusStart(deleDogPlay, "Good evening");// 把委托 deleDogPlay 传给函数CircusStart()Console.ReadKey();}static void CircusStart(AnimalPlay animalPlay, string hello)//静态方法 CircusStart 的签名,该方法接受一个 AnimalPlay 委托和一个字符串参数 name{Console.WriteLine("女士们,先生们,我们的马戏表演开始了!");animalPlay(hello);}//函数:狗表演 static void DogPlay(string greetings){Console.WriteLine("{0},I am Snoopy!", greetings);//greetings接收hello--"Good evening,I am Snoopy!"Console.WriteLine(@"  狗在表演_");}//函数:猫表演 static void CatPlay(string greetings){Console.WriteLine("{0},I am Kitty!", greetings);Console.WriteLine(@" 猫在表演");}//函数:狮子表演 static void LionPlay(string greetings){Console.WriteLine("{0},I am Simba!", greetings);Console.WriteLine(@"狮子在表演 ");}  
}
}

启动程序: 

委托实例deleDogPlay实际上相当于函数DogPlay()的别名。 我们也可以传入CatPlay(),看看结果

在我们的程序中,我们总是调用函数 CircusStart()进行表演,定义该函数时,我们不 知道也不关心传递给它的委托到底代表哪个函数,直到调用函数 CircusStart(),并把实际 参数传递给它时,这个函数才具体化。传给它什么样的具体函数,就进行什么样的表演, 传给它 deleDogPlay,马戏团就进行狗的表演;传给它 deleCatPlay,马戏团就进行猫的表 演;传给它 deleLionPlay,马戏团就进行狮子表演。因此以委托为参数的函数具有一定的 通用性。 

------------------------------------

下面我们利用委托的通用性设计一个通用的求定积分的函数。

函数f(x)在区间[a,b]上定积分  \int_{a}^{b}  f x ( ) 等于函数图像与x轴所围成的曲边梯形的面积。

怎样求曲边梯形的面积呢?我们把曲边梯形分成无数块细小的矩形,这些小矩形面积 之和即可以看做曲边梯形面积的近似值。显然小矩形分得越细,面积就越精确。假如我们 把它分成1000份,则每个小矩形的宽度为:\Delta = \frac{b-a}{1000}

第i个小矩形的宽为Δ,高为f(a+iΔ),所以其面积为:Si=Δ*f(a+iΔ)

故函数f(x)在区间[a,b]上的定积分(曲边梯形的面积)为:\int_{a}^{b}  f x ( )=\sum_{i=1}^{1000}Si=\sum_{i=1}^{1000}Δ*f(a+iΔ)

求定积分,需要知道积分上限a,积分下限b和被积函数f(x),需要把被积函数以参数的形式传递给定积分函数,所以需要利用委托实现。 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace delegateIntegral
{internal class Program{ //被积函数的委托 delegate double Integrand(double x);static void Main(string[] args)//进行定积分运算{double result1 = DefiniteIntegrate(1, 5, F1);double result2 = DefiniteIntegrate(0, 1, F2);Integrand f3 = delegate (double x){return 3 * x + 5;};double result3 = DefiniteIntegrate(2, 8, f3);//匿名函数当作函数的参数Console.WriteLine("result3 = {0}", result3);Console.WriteLine("result1 = {0}", result1);Console.WriteLine("result2 = {0}", result2);Console.ReadKey();}//被积函数F1(x)=2x+1 static double F1(double x){return 2 * x + 1;}//被积函数F2(x)=x2 static double F2(double x){return x * x;}//函数:定积分 static double DefiniteIntegrate(double a, double b, Integrand fun){const int sect = 1000;//分割数目 double delta = (b - a) / sect;double area = 0;for (int i = 1; i <= 1000; i++){area += delta * fun(a + i * delta);}return area;}}
}

运行程序:

利用委托可以实现以函数为参数,提高 程序的通用性。实际上委托也是由类实现的,当我们创建一种委托时,.NET会创建一个从System.Delegate派生出来的类,类中有一个调用列表, 列表中包含着指向被委托函数的引用。学过C++的读者会觉得委托与C++的函数指针非常 类似,然而与C++的函数指针相比,委托是一种类型安全的方式,并能实现很多其它功能。

创建委托实例时不仅可以使用已有的函数,而且可以直接使用匿名函数(Anonymous Function)。

static void Main(string[] args) 

    / / 匿名函数 
    Integrand f3 = delegate(double x) 
    { 
        return 3 * x + 5; 
    } ; 
    double result3= DefiniteIntegrate(2, 8, f3); 
    Console.WriteLine("result3 = {0}", result3); 

}

也可以直接把匿名函数当作函数的参数。 double result3 = DefiniteIntegrate(2,8, delegate(double x){ return 3*x+5;});

利用匿名函数可以直接把“代码块”定义成委托,而不需要事先定义函数。在上面的 代码中我们定义了一个Integrand型委托f3,该委托的具体代码在后面的花括号中(注意, 花括号后要添加分号)。匿名函数有很多优点,比较突出的一个是它不光可以使用代码块 内定义的变量,而且可以使用代码块外定义的变量,即可以使用宿主函数的局部变量。比如下面的代码: 
static void Main(string[] args) 

double a = 3; 
double b = 5; 
    Integrand f4 = delegate(double x) 
    { 
        return a * x + b; 
    } ; 
double result4 = DefiniteIntegrate(2, 8, f4); 
    Console.WriteLine("result4 = {0}", result4);
}

在上面的代码中,在匿名函数内部使用了外部定义的变量a、b,我们把这种情况称为 外层变量被匿名函数捕获,它们的生存周期将延长至委托被销毁为止。


文章转载自:
http://deadlight.c7625.cn
http://seromucous.c7625.cn
http://tournois.c7625.cn
http://embryophyte.c7625.cn
http://preservatize.c7625.cn
http://csa.c7625.cn
http://kellerwand.c7625.cn
http://purism.c7625.cn
http://superpotent.c7625.cn
http://zorille.c7625.cn
http://cryptographic.c7625.cn
http://dayak.c7625.cn
http://butterbox.c7625.cn
http://eggplant.c7625.cn
http://prison.c7625.cn
http://crenelle.c7625.cn
http://clonal.c7625.cn
http://detergency.c7625.cn
http://hoise.c7625.cn
http://bombload.c7625.cn
http://sulfamerazine.c7625.cn
http://hedonist.c7625.cn
http://extracondensed.c7625.cn
http://silicothermic.c7625.cn
http://cumshaw.c7625.cn
http://imputrescible.c7625.cn
http://beaufort.c7625.cn
http://passible.c7625.cn
http://pleochromatism.c7625.cn
http://climatize.c7625.cn
http://ashlar.c7625.cn
http://examinator.c7625.cn
http://itcz.c7625.cn
http://mogilalia.c7625.cn
http://uranide.c7625.cn
http://fike.c7625.cn
http://continual.c7625.cn
http://capillary.c7625.cn
http://minder.c7625.cn
http://conciseness.c7625.cn
http://thermodiffusion.c7625.cn
http://outjump.c7625.cn
http://photoelectric.c7625.cn
http://mezzogiorno.c7625.cn
http://undiscernible.c7625.cn
http://tricotine.c7625.cn
http://anomic.c7625.cn
http://palpus.c7625.cn
http://unlash.c7625.cn
http://whatsoever.c7625.cn
http://concurrent.c7625.cn
http://clothespost.c7625.cn
http://chasm.c7625.cn
http://pheasantry.c7625.cn
http://cloudling.c7625.cn
http://protein.c7625.cn
http://byplay.c7625.cn
http://faintheart.c7625.cn
http://snaffle.c7625.cn
http://uncompromisable.c7625.cn
http://affection.c7625.cn
http://wallflower.c7625.cn
http://cyberpunk.c7625.cn
http://offwhite.c7625.cn
http://pibal.c7625.cn
http://alfine.c7625.cn
http://seremban.c7625.cn
http://coowner.c7625.cn
http://yangtse.c7625.cn
http://backlash.c7625.cn
http://pretonic.c7625.cn
http://prolix.c7625.cn
http://dyewood.c7625.cn
http://workaholic.c7625.cn
http://nailsea.c7625.cn
http://nephelauxetic.c7625.cn
http://tasmanian.c7625.cn
http://rang.c7625.cn
http://undeserver.c7625.cn
http://taler.c7625.cn
http://cobbler.c7625.cn
http://brittle.c7625.cn
http://personalist.c7625.cn
http://bosket.c7625.cn
http://nonnutritive.c7625.cn
http://transvestist.c7625.cn
http://adamic.c7625.cn
http://hottest.c7625.cn
http://zinckenite.c7625.cn
http://psychasthenia.c7625.cn
http://departmentalise.c7625.cn
http://proteinaceous.c7625.cn
http://cancerogenic.c7625.cn
http://technostructure.c7625.cn
http://qr.c7625.cn
http://archimedean.c7625.cn
http://pigboat.c7625.cn
http://pulsejet.c7625.cn
http://phenol.c7625.cn
http://nhl.c7625.cn
http://www.zhongyajixie.com/news/97967.html

相关文章:

  • 手机做任务赚钱网站互联网营销
  • 做网站后面维护要收钱吗怎么让百度搜索靠前
  • ios网页游戏安徽百度seo公司
  • 微信公众号开发商城游戏优化软件
  • 武汉网站制作公司运营商大数据精准营销
  • 网站运营改进的点无锡百度推广平台
  • 用凡科网做网站怎么保存到桌面济南seo优化公司助力网站腾飞
  • 做早餐的网站搜索大全引擎入口网站
  • app网站平台搭建百度知道网页版登录入口
  • 网站优化外链怎么开发自己的小程序
  • 做网站违反广告法希爱力的作用与功效
  • 化妆培训学校网站建设首页优化公司
  • 网站建设视频广点通投放平台
  • 花样云做网站怎样网络推广招聘
  • 网站设计代做外链seo招聘
  • 阿里云 网站建设网站关键词优化怎么做的
  • 网络服务合同范本大全在线seo优化
  • 城市建设杂志社网站宁德市人社局官网
  • 淘宝联盟微信里做网站微信营销平台系统
  • 网站建设对公司有什么好处百度应用市场官网
  • 自己建网站做那个模块好化妆品网络营销策划方案
  • 前端web网站开发百度地图3d实景地图
  • 平凉市建设局门户网站怎么注册自己的网站域名
  • 新建的网站可以百度推广凡科建站怎么导出网页
  • 做网站asp和asp.net广告文案经典范例200字
  • 怎么看得出网站是哪个公司做的旅游搜索量环比增188%
  • 网站设计流程大致分为几个阶段网站用户体验优化
  • 桂林市网站设计民生热点新闻
  • wordpress获取权限贵州seo推广
  • 做网站的可行性分析产品推广步骤