I tried to parse the generated C # executable, but I could not come to a conclusion. I would like to know that if there are really special entities for C # CLR delegates or just a compiler sackler?
I ask this because I am implementing a language that compiles in C #, and it would be much more interesting for me to compile anonymous functions as classes than as delegates. But I don’t want to use a design that I will regret later as they can be heavier in memory (I think Java PermGen bases my survey. Although I know that the CLR does not exist).
Thanks!
- change
to be a little more clear, I would like to know if there are (and what) differences between:
void Main() { Func<int, int, int> add = delegate(int a, int b) {return a + b;}; }
and for example
class AnonFuncion__1219023 : Fun3 { public override int invoke(int a, int b) { return a + b; } }
- edit
I think there may be a big difference between:
class Program { static int add(int a, int b) { return a + b; } static void Main() { Func<int, int, int> add = Program.add; } }
and
class Function__432892 : Fun3 { public override int invoke(int a, int b) { return Program.add(a, b); } }
I read somewhere that the syntax is Func<int, int, int> add = Program.add; - this is only sugar for Func<int, int, int> add = delegate(int a, int b) { return Program.add; }; Func<int, int, int> add = delegate(int a, int b) { return Program.add; }; . But I really don't know if this is true. I could also see that the C # compiler already caches all of these instances, so they are built only once. I could do the same with my compiler.
c # clr internals delegates il
Waneck
source share