2
Answers

default constructor?

George George

George George

16y
2.7k
1

Hello everyone,


From the IL for the following code, seems there is default constructor for both value and reference types which accepts null argument? Are they added by CLR directly (from .locals init IL statement)?

[Code]
    class Program
    {
        struct Foo
        {
            int abc;
        }

        class Goo
        {
            public int abc;
        }

       
        static void Main(string[] args)
        {
            Foo f;

            Goo g;

            return;
        }
    }

.method private hidebysig static void Main(string[] args) cil managed
{
    .entrypoint
    .maxstack 0
    .locals init (
        [0] valuetype TestStruct1.Program/Foo f,
        [1] class TestStruct1.Program/Goo g)
    L_0000: nop
    L_0001: br.s L_0003
    L_0003: ret
}
[/Code]


thanks in advance,
George

Answers (2)