Long long time ago, there was a .NET/CLR

Recently I had a quite interesting opportunity to talk about .Net fundamentals.
Though using C# for various reasons and framework I am aware that I lack the real bits and bolts of the language & the framework.

An interesting (and quite basic topic) - FYI.

What will b1 and b2 be (and why)?

            object s1 = "apple";
            object s2 = "apple";
            bool b1 = s1 == s2;

            object i1 = 1;
            object i2 = 1;
            bool b2 = i1 == i2;

I remembered that I need the fundamentals of boxing and unboxing, etc; therefore my answer was ok, however the reasoning was not ok. Some background here.
The solution is (true, false). My understanding about the reasons: b1: Reference, however string is immutable thus CLR maps to same address; b2: boxed value type becomes reference type, thus different pointers.

No comments:

Post a Comment