C # Simple example of container and unboxing operation

Source: Internet
Author: User
In this paper, a simple example of the implementation of C # Boxing and unboxing operations, simple boxing is to convert a value type to a reference type, unboxing is to convert the reference type to a value type, is involved in the use of stacks and heaps of things, the people who have learned C # should know, so here is not shiver, this example code is also for C # Beginner's, very simple.

The specific implementation code is as follows:

Using system;using system.collections.generic;using system.linq;using system.text;namespace UnBoxing{  class Program  {    static void Main (string[] args)    {      int i = 123;//declares a variable i of type int and initializes to 123      object obj = i; Execute boxing Operation      Console.WriteLine ("Boxing operation: value {0}, after boxing object is {1}", I, obj);      int j = (int) obj;//perform the unboxing Operation      Console.WriteLine ("Unboxing: Boxed object is {0} with a value of {1}", obj, j);      Console.ReadLine ();}}}  
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.