Вопрос

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?

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top