Jonathan James
Jonathan James

Reputation: 61

Weird function __Boxed<int> for boxing and unboxing after decompiling

Hello I'm having some issues trying to find a replacement to this portion of code after decompiling an executable.

I can't seem to find a replacement in c# for __Boxed anywhere online

        DateTime startTime = dev.runningList[0].startTime;
        // ISSUE: variable of a boxed type
        __Boxed<int> day = (System.ValueType) startTime.Day;
        objArray2[0] = (object) day;
        object[] objArray3 = objArray1;

Upvotes: 2

Views: 2392

Answers (1)

Martin
Martin

Reputation: 16433

This code is boxing the integer value of startTime.Day into an object. The reason you are seeing __Boxed<T> is probably a feature of the decompilation tool you are using.

When you need to use a value type as an object, the compiler will box it in order that it is treated as an object (heap based) as opposed to a value type (stack based).

For your own code you don't need to box the int, you could just write this:

DateTime startTime = dev.runningList[0].startTime;
int day = startTime.Day;
objArray2[0] = day;

When compiling this to IL, day will be boxed by the compiler as needed - you do not need to manually box it.

Upvotes: 5

Related Questions