当前位置:网站首页>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!");
}
}
}
边栏推荐
- Enter the length of three sides of the triangle through the user, and calculate the area of the triangle, where the length is a real number
- Deeply understand the mvcc mechanism of MySQL
- Flinksql can directly create tables and read MySQL or Kafka data on the client side, but how can it automatically flow and calculate?
- Enable SASL authentication for memcached
- ImportError: No module named examples. tutorials. mnist
- 双链笔记·思源笔记综合评测:优点、缺点、评价
- Everything comes to him who waits
- [ArcGIS user defined script tool] vector file generates expanded rectangular face elements
- OpenStack节点地址改变
- T430 toss and install OS majave 10.14
猜你喜欢

4. Wireless in vivo nano network: electromagnetic propagation model and key points of sensor deployment

Summary of error prone knowledge points: Calculation of define s (x) 3*x*x+1.
![Sword finger offer03 Repeated numbers in the array [simple]](/img/cf/c1ad2f2a45560b674b5b8c11fed244.png)
Sword finger offer03 Repeated numbers in the array [simple]

LeetCode 0556. Next bigger element III - end of step 4

Application of ncnn Neural Network Computing Framework in Orange Pi 3 Lts Development Board

Togaf certification self-study classic v2.0

Differences between initial, inherit, unset, revert and all

阿里大于发送短信(用户微服务--消息微服务)

Node. Js: use of express + MySQL

Xctf mobile--rememberother problem solving
随机推荐
TOGAF认证自学宝典V2.0
[exercise 7] [Database Principle]
Record your vulnhub breakthrough record
(latest version) WiFi distribution multi format + installation framework
剑指Offer07. 重建二叉树
idea将web项目打包成war包并部署到服务器上运行
[combinatorics] permutation and combination (multiple set permutation | multiple set full permutation | multiple set incomplete permutation all elements have a repetition greater than the permutation
Flinksql can directly create tables and read MySQL or Kafka data on the client side, but how can it automatically flow and calculate?
Glide question you cannot start a load for a destroyed activity
Drop down refresh conflicts with recyclerview sliding (swiperefreshlayout conflicts with recyclerview sliding)
How to get user location in wechat applet?
Redhat5 installing socket5 proxy server
4. 无线体内纳米网:电磁传播模型和传感器部署要点
剑指Offer05. 替换空格
低代码平台国际化多语言(i18n)技术方案
The latest version of lottery blind box operation version
Day 1 of kotlin learning: simple built-in types of kotlin
elastic_ L02_ install
Brief introduction to mvcc
studio All flavors must now belong to a named flavor dimension. Learn more