当前位置:网站首页>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!");
}
}
}
边栏推荐
- Idea packages the web project into a war package and deploys it to the server to run
- (latest version) WiFi distribution multi format + installation framework
- Four problems and isolation level of MySQL concurrency
- 十條職場規則
- 【习题七】【数据库原理】
- Eureka self protection
- CNN MNIST handwriting recognition
- 阿里 & 蚂蚁自研 IDE
- [exercise 7] [Database Principle]
- Deeply understand the mvcc mechanism of MySQL
猜你喜欢

如何在微信小程序中获取用户位置?

Leetcode234 palindrome linked list

The latest version of lottery blind box operation version

2021 autumn Information Security Experiment 1 (password and hiding technology)

剑指Offer05. 替换空格

Eureka自我保护

Grid connection - Analysis of low voltage ride through and island coexistence

Differences between initial, inherit, unset, revert and all

Xctf mobile--app3 problem solving

【ManageEngine】IP地址扫描的作用
随机推荐
Enable SASL authentication for memcached
02_ Lock the code, and don't let the "lock" become a worry
The latest version of lottery blind box operation version
记录自己vulnhub闯关记录
Social community forum app ultra-high appearance UI interface
Gan totem column bridgeless boost PFC (single phase) seven PFC duty cycle feedforward
Apache Mina Development Manual
Summary of error prone knowledge points: Calculation of define s (x) 3*x*x+1.
最新版盲盒商城thinkphp+uniapp
Redhat5 installing socket5 proxy server
Swift bit operation exercise
Four problems and isolation level of MySQL concurrency
Sword finger offer14 the easiest way to cut rope
Powerful avatar making artifact wechat applet
【習題七】【數據庫原理】
idea将web项目打包成war包并部署到服务器上运行
Sqoop1.4.4原生增量导入特性探秘
Two solutions of leetcode101 symmetric binary tree (recursion and iteration)
初入职场,如何快速脱颖而出?
[judgment question] [short answer question] [Database Principle]