惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
N
News and Events Feed by Topic
P
Privacy International News Feed
The Hacker News
The Hacker News
Schneier on Security
Schneier on Security
C
Cybersecurity and Infrastructure Security Agency CISA
Security Latest
Security Latest
L
LINUX DO - 最新话题
阮一峰的网络日志
阮一峰的网络日志
Cisco Talos Blog
Cisco Talos Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
The Cloudflare Blog
博客园 - 【当耐特】
博客园 - Franky
P
Privacy & Cybersecurity Law Blog
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
月光博客
月光博客
D
Docker
Webroot Blog
Webroot Blog
The GitHub Blog
The GitHub Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
W
WeLiveSecurity
S
Security Affairs
Martin Fowler
Martin Fowler
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Security Archives - TechRepublic
Security Archives - TechRepublic
Microsoft Azure Blog
Microsoft Azure Blog
C
CERT Recently Published Vulnerability Notes
B
Blog
L
Lohrmann on Cybersecurity
T
Threatpost
量子位
S
Schneier on Security
V
Visual Studio Blog
S
Securelist
T
The Exploit Database - CXSecurity.com
Scott Helme
Scott Helme
V
Vulnerabilities – Threatpost
aimingoo的专栏
aimingoo的专栏
The Register - Security
The Register - Security
I
Intezer
Stack Overflow Blog
Stack Overflow Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
博客园 - 聂微东
小众软件
小众软件
罗磊的独立博客
雷峰网
雷峰网
Recorded Future
Recorded Future

博客园 - 数迹

1.winform中App.config配置mssql连接字符串 where关键字 1.params 关键字 1.创建实体类UserInfo 1. UserInfo表的创建 3.SqlCommand组件 2.在DbHelper.cs 中使用连接字符串 事件委托1 多播委托 委托总结:委托提供了 A类的对象 调用 B类对象的同一类方法 的能力。 委托3--委托声明比较 委托1 sql提示注册表中无 \100\ConfigurationState的解决方法 - 数迹 - 博客园 安装SQL server 提示重新启动计算机失败怎么解决 DataGridView插入指定类型的列 菜单制作过程笔记1 ${pagecontext.request.contextpath}绝对路径理解 eclipse中修改JSP模板中的默认编码 hibernate的ddl-auto属性
委托2 文心快码
数迹 · 2026-02-10 · via 博客园 - 数迹

仅仅记录学习过程,理解不一定对!

C#中,delegate 实际上是一种特殊的类型,它用于定义方法的类型。这种类型被称为委托(Delegate。委托是C#中的一种类型,它允许你将一个或多个方法作为参数传递给另一个方法,或者在某个时间点调用这些方法。

委托的基本概念

  1. 方法签名:委托定义了它可以引用的方法的签名,即方法的返回类型和参数列表。
  2. 实例化和调用:你可以实例化一个委托,使其引用一个具有匹配签名的方法。之后,你可以像调用普通方法一样调用这个委托实例。
  3. 多播委托C# 支持多播委托,这意味着一个委托可以包含对多个方法的引用,当委托被调用时,这些方法都会被依次调用。

示例

下面是一个简单的委托示例:

csharpCopy Code

using System;

delegate int MathOperation(int x, int y);

class Program

{

    static int Add(int x, int y)

    {

        return x + y;

    }

    static int Multiply(int x, int y)

    {

        return x * y;

    }

    static void Main()

    {

        MathOperation add = Add; // 实例化委托,引用Add方法

        MathOperation multiply = Multiply; // 实例化委托,引用Multiply方法

        Console.WriteLine("Add: " + add(5, 3)); // 输出: Add: 8

        Console.WriteLine("Multiply: " + multiply(5, 3)); // 输出: Multiply: 15

    }

}

在这个例子中,MathOperation 是一个委托类型,它定义了一个接受两个int参数并返回一个int结果的签名。我们创建了两个方法AddMultiply,它们分别符合这个签名。然后我们创建了MathOperation类型的变量addmultiply,并将它们分别指向了AddMultiply方法。最后,我们通过这些委托变量调用了相应的方法。

总结

因此,在C#中,“delegate”实际上是委托,用于定义方法的类型并允许将方法作为参数传递或在运行时调用它们。这是C#中实现回调和事件处理机制的基础。

c#delegate是代理还是委托

在C#中,delegate 实际上是一种特殊的类型,它用于定义方法的类型。这种类型被称为“委托(Delegate)”。委托是C#中的一种类型,它允许你将一个或多个方法作为参数传递给另一个方法,或者在某个时间点调用这些方法。

委托的基本概念

  1. 方法签名‌:委托定义了它可以引用的方法的签名,即方法的返回类型和参数列表。
  2. 实例化和调用‌:你可以实例化一个委托,使其引用一个具有匹配签名的方法。之后,你可以像调用普通方法一样调用这个委托实例。
  3. 多播委托‌:C# 支持多播委托,这意味着一个委托可以包含对多个方法的引用,当委托被调用时,这些方法都会被依次调用。

示例

下面是一个简单的委托示例:

using System; delegate int MathOperation(int x, int y); class Program { static int Add(int x, int y) { return x + y; } static int Multiply(int x, int y) { return x * y; } static void Main() { MathOperation add = Add; // 实例化委托,引用Add方法 MathOperation multiply = Multiply; // 实例化委托,引用Multiply方法 Console.WriteLine("Add: " + add(5, 3)); // 输出: Add: 8 Console.WriteLine("Multiply: " + multiply(5, 3)); // 输出: Multiply: 15 } }

在这个例子中,MathOperation 是一个委托类型,它定义了一个接受两个int参数并返回一个int结果的签名。我们创建了两个方法AddMultiply,它们分别符合这个签名。然后我们创建了MathOperation类型的变量addmultiply,并将它们分别指向了AddMultiply方法。最后,我们通过这些委托变量调用了相应的方法。

总结

因此,在C#中,“delegate”实际上是“委托”,用于定义方法的类型并允许将方法作为参数传递或在运行时调用它们。这是C#中实现回调和事件处理机制的基础。