问题描述
我正在尝试学习一些 c# 编码,并想知道 c# 中是否包含函数指针的 c++ 概念.我看到有诸如代表之类的东西.它们是同一个概念吗?还是它们在更基本的层面上有所不同?
I am trying to learn some c# coding and wondering if the c++ concept of function pointers is included in c#. I see there are such things as delegates. Are they the same concept? or do they differ on a more fundamental level?
推荐答案
委托本质上是函数指针,但是内置了额外的多播能力.所以你可以将多个函数分配给同一个委托,它们都会被依次调用当委托被调用时.
Delegates are essentially function pointers, but with extra multicast capabilities built in. So you can assign several functions to the same delegate, and they will all be called in sequence when the delegate is called.
委托还具有内置的异步接口,并且在将新功能分配给委托时(以及在 .NET 4 中,在传递委托时)具有共同/相反的差异
Delegates also have built-in asynchronous interfaces, and have co/contra variance when assigning new functions to a delegate (and, in .NET 4, when passing delegates around)
这篇关于c#中有函数指针吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!