Question

What I understand unboxing is when I take a object and unbox it to valuetype like the MSDN example:

int i = 123;
object o = i;  
o = 123;
i = (int)o;  // unboxing

So I just was thinking, can a string be unboxed? I think, No it can't because there is no valuetype that can represent a string. Am I right?

Was it helpful?

Solution

You're right. A string can't be unboxed because only value types are subject to boxing and unboxing; a string is a reference type.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top