当前位置:网站首页>C graphical tutorial (Fourth Edition)_ Chapter 13 entrustment: what is entrustment? P238
C graphical tutorial (Fourth Edition)_ Chapter 13 entrustment: what is entrustment? P238
2022-07-03 12:52:00 【superfreak】
using System;
delegate void MyDel(int value);// Declared a delegate , The return value is void, The accepted parameter is int
// namely : This delegate can represent such a function : no return value , And accept a parameter of type int Parameters of
namespace Chapter13Delegate_131WhatisaDelegate
{
class Program
{
void PrintLow(int value)// The return value is void The parameter is one int Function of type
{
Console.WriteLine("{0}-Low Value",value);
}
void PrintHigh(int value)// The return value is void The parameter is one int Another function of type
{
Console.WriteLine("{0}-High Value", value);
}
static void Main(string[] args)
{
Program program = new Program();
MyDel del;
// Random number generation 0-----99
Random rand = new Random();
int randomValue = rand.Next(99);
// Create a containing PrintLow or PrintHigh And assign it to del Variable
del = randomValue < 50 ? new MyDel(program.PrintLow) : new MyDel(program.PrintHigh);
// The above is to assign a delegate to a function , Or to whom this Commission is given ? Which function is given is determined , But it doesn't call
del(randomValue);// Perform entrusted
// The above statement is the real use of this delegate Add this Random values to run this delegate , It runs the function represented by the delegate .
Console.WriteLine("Hello World!");
}
}
}
边栏推荐
- [Exercice 5] [principe de la base de données]
- Nodejs+Express+MySQL实现登陆功能(含验证码)
- Differences between initial, inherit, unset, revert and all
- Using swift language features, write a pseudo-random number generator casually
- 【数据挖掘复习题】
- Grid connection - Analysis of low voltage ride through and island coexistence
- Sword finger offer05 Replace spaces
- Apache Mina开发手册
- Low code platform international multilingual (I18N) technical solution
- Openstack node address change
猜你喜欢

并网-低电压穿越与孤岛并存分析

电压环对 PFC 系统性能影响分析

Sword finger offer06 Print linked list from end to end

Quick learning 1.8 front and rear interfaces

Sword finger offer07 Rebuild binary tree

【ManageEngine】IP地址扫描的作用

Gan totem column bridgeless boost PFC (single phase) seven PFC duty cycle feedforward

ncnn神經網絡計算框架在香柳丁派OrangePi 3 LTS開發板中的使用介紹

How to convert a decimal number to binary in swift

studio All flavors must now belong to a named flavor dimension. Learn more
随机推荐
How to get user location in wechat applet?
01 three solutions to knapsack problem (greedy dynamic programming branch gauge)
Method overloading and rewriting
Xctf mobile--app1 problem solving
It feels great to know you learned something, isn‘t it?
The latest version of blind box mall thinkphp+uniapp
Summary of error prone knowledge points: Calculation of define s (x) 3*x*x+1.
Approve iPad, which wants to use your icloud account
Tianyi ty1208-z brush machine detailed tutorial (free to remove)
Nodejs+Express+MySQL实现登陆功能(含验证码)
【R】【密度聚类、层次聚类、期望最大化聚类】
Sword finger offer09 Implementing queues with two stacks
Export the entire Oracle Database
【计网】第三章 数据链路层(2)流量控制与可靠传输、停止等待协议、后退N帧协议(GBN)、选择重传协议(SR)
4. 无线体内纳米网:电磁传播模型和传感器部署要点
02_ Lock the code, and don't let the "lock" become a worry
Keep learning swift
[combinatorics] permutation and combination (the combination number of multiple sets | the repetition of all elements is greater than the combination number | the derivation of the combination number
Express abstract classes and methods
【ArcGIS自定义脚本工具】矢量文件生成扩大矩形面要素