質問

I have this code after decompile

    SampleClass sampleClass;
    SampleClass <>g__initLocal0;
    int y;
    sampleClass = null;
Label_0018:
    try
    {
        <>g__initLocal0 = new SampleClass();
        <>g__initLocal0.X = 5;
        <>g__initLocal0.Y = 10;
        sampleClass = <>g__initLocal0;
        goto Label_003A;
    }
    catch (Exception)
    {
    Label_0035:
        goto Label_003A;
    }
Label_003A:
    y = sampleClass.Y;

I don't know what mean operator/symbol <> before some operations. Does somebody know?

役に立ちましたか?

解決

It's a compiler generated name - the <> characters are legal for identifiers in IL, but not in C#. So, the compiler knows it can generate names containing such characters without any chance that the name will conflict with a name you've used in your code.

In this particular case, <>g__initLocal0 is a new variable that has been introduced to hold a newly constructed instance of a class which is being initialized using initializer syntax. The original code was:

sampleClass = new SampleClass() { X = 5, Y = 10};

It's introduced to avoid sampleClass being observed with the partially constructed instance - after new SampleClass() has executed but before the assignments to X and Y occur. I.e. if Y = 10 throws an exception, it ensures that sampleClass remains null and not a new SampleClass with X set to 5 and some unknown value for Y.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top