当前位置:网站首页>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!");
}
}
}
边栏推荐
- Ali & ant self developed IDE
- 4. 无线体内纳米网:电磁传播模型和传感器部署要点
- [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
- 【习题五】【数据库原理】
- Apache Mina开发手册
- elastic_ L01_ summary
- Application of ncnn Neural Network Computing Framework in Orange Pi 3 Lts Development Board
- Sword finger offer06 Print linked list from end to end
- Dix règles de travail
- 01_ Using the concurrent tool class library, is thread safety safe
猜你喜欢
Eureka self protection
Glide question you cannot start a load for a destroyed activity
Quick learning 1.8 front and rear interfaces
Brief introduction to mvcc
最新版盲盒商城thinkphp+uniapp
[ArcGIS user defined script tool] vector file generates expanded rectangular face elements
2021 autumn Information Security Experiment 1 (password and hiding technology)
Record your vulnhub breakthrough record
The upward and downward transformation of polymorphism
社交社区论坛APP超高颜值UI界面
随机推荐
The solution to change the USB flash disk into a space of only 2m
Express abstract classes and methods
Differences and connections between final and static
剑指Offer10- I. 斐波那契数列
剑指Offer06. 从尾到头打印链表
initial、inherit、unset、revert和all的区别
Project video based on Linu development
Record your vulnhub breakthrough record
studio All flavors must now belong to a named flavor dimension. Learn more
【计网】第三章 数据链路层(2)流量控制与可靠传输、停止等待协议、后退N帧协议(GBN)、选择重传协议(SR)
Kung Fu pays off, and learning is done
Cache penetration and bloom filter
Airflow installation jump pit
Huffman coding experiment report
Ali & ant self developed IDE
Gan totem column bridgeless boost PFC (single phase) seven PFC duty cycle feedforward
It feels great to know you learned something, isn‘t it?
【習題七】【數據庫原理】
Detailed explanation of the most complete constraintlayout in history
Sword finger offer03 Repeated numbers in the array [simple]