are there function pointers in c#?

前端 未结 6 1277
后悔当初
后悔当初 2020-12-07 01:40

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 co

6条回答
  •  悲&欢浪女
    2020-12-07 02:22

    Not in the classical C/C++ sense, no. But the concept is somewhat similar - .NET introduces the concept of delegates to handle situations where you need a variable to invoke a method upon. Delegates cannot be "twiddled" with as pointers can and there is type safety built-in.

    If you use C-style function pointers "correctly" the concepts are similar. But there seems to be a lot of legacy code which does funny manipulations of the pointers to skirt around type-safety or what-not.

提交回复
热议问题