是什么在C#和函数指针在C ++中的代表有什么区别?

编程入门 行业动态 更新时间:2024-10-25 18:33:22
本文介绍了是什么在C#和函数指针在C ++中的代表有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

可能重复:结果的是否有函数指针在C#?

我M有意寻找在C#委托之间的差异, 在C ++函数指针。

I'm interested in finding the difference between delegate in C# and function pointer in C++.

推荐答案

在C#中的委托是一个内置的迭代器类型安全的函数指针。

A delegate in C# is a type-safe function pointer with a built in iterator.

它保证指向与指定的签名有效的函数(不像C,其中的指针可以转换为指向谁知道是什么)。它还支持通过多种约束功能迭代的概念。

It's guaranteed to point to a valid function with the specified signature (unlike C where pointers can be cast to point to who knows what). It also supports the concept of iterating through multiple bound functions.

在C#中,代表们的多播的意思是他们可以通过多种功能迭代。例如:

In C#, delegates are multi-cast meaning they can iterate through multiple functions. For example:

class Program { delegate void Foo(); static void Main(string[] args) { Foo myDelegate = One; myDelegate += Two; myDelegate(); // Will call One then Two } static void One() { Console.WriteLine("In one.."); } static void Two() { Console.WriteLine("In two.."); } }

更多推荐

是什么在C#和函数指针在C ++中的代表有什么区别?

本文发布于:2023-07-28 14:06:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1231623.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:指针   有什么区别   函数   代表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!