当前位置:网站首页>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!");
}
}
}
边栏推荐
- Applet wxss introduction
- 【习题六】【数据库原理】
- Glide 4.6.1 API initial
- 初入职场,如何快速脱颖而出?
- Dix règles de travail
- GCN thinking - word2vec directly calculates text classification
- 4. 无线体内纳米网:电磁传播模型和传感器部署要点
- Write a simple nodejs script
- [exercice 7] [principe de la base de données]
- Kotlin notes - popular knowledge points asterisk (*)
猜你喜欢
Glide question you cannot start a load for a destroyed activity
Solve the problem of VI opening files with ^m at the end
【R】【密度聚类、层次聚类、期望最大化聚类】
The latest version of blind box mall thinkphp+uniapp
Eureka self protection
LeetCode 0556. Next bigger element III - end of step 4
【计网】第三章 数据链路层(2)流量控制与可靠传输、停止等待协议、后退N帧协议(GBN)、选择重传协议(SR)
Sword finger offer03 Repeated numbers in the array [simple]
Togaf certification self-study classic v2.0
Powerful avatar making artifact wechat applet
随机推荐
Swift5.7 扩展 some 到泛型参数
Ali & ant self developed IDE
CNN MNIST handwriting recognition
Tianyi ty1208-z brush machine detailed tutorial (free to remove)
Nodejs+express+mysql realizes login function (including verification code)
02_ Lock the code, and don't let the "lock" become a worry
Take you to the installation and simple use tutorial of the deveco studio compiler of harmonyos to create and run Hello world?
ImportError: No module named examples. tutorials. mnist
[exercise 7] [Database Principle]
[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
十條職場規則
I'm too lazy to write more than one character
Differences and connections between final and static
【综合题】【数据库原理】
Kung Fu pays off, and learning is done
ncnn神经网络计算框架在香橙派OrangePi 3 LTS开发板中的使用介绍
Grid connection - Analysis of low voltage ride through and island coexistence
Exploration of sqoop1.4.4 native incremental import feature
Xctf mobile--app3 problem solving
Dix règles de travail