Thursday, July 23, 2009

Boxing & UnBoxing

C# provides two types of variables they are Value types and Reference Types. Value Types are stored on the stack and Reference types are stored on the heap. The conversion of value type to reference type is known as boxing and converting reference type back to the value type is known as unboxing.


class Test
    static void Main() {
        int i = 1;
        object o = i;        // boxing
        int j = (int) o;     // unboxing

No comments:

Creative Commons License
Disclaimers:We have tried hard to provide accurate information, as a user, you agree that you bear sole responsibility for your own decisions to use any programs, documents, source code, tips, articles or any other information provided on this Blog.