C # Base value classes and reference types

Source: Internet
Author: User

Value type: int double char decimal bool enum struct
Reference type: string Array custom Class Collection Object interface

// value passing and reference passing            int Ten ;             int n2 = N1;              - ;            Console.WriteLine (N1); // Ten            Console.WriteLine (n2); //  -            Console.readkey ();

If it is a reference type, the last

person P1 =NewPerson ();//This is a reference typeP1. Name ="Zhang San"; Person P2=P1; P2. Name="John Doe"; //P1. Name = "1223";Console.WriteLine (P2. Name);//It's the last 1233 anyway .Console.WriteLine (P1. Name);//It's the last one anyway .Console.readkey ();//John Doe//if there is no P1 here. Name = "1223"; This is Li Shili .

Packing, unpacking
Boxing: Converts a value type to a reference type.
Unboxing: Converts a reference type to a value type.
Look at whether the two types have occurred boxing or unpacking, to see if there is an inheritance relationship between the two types of

Avoidance of unpacking and crating

This place does not take place any type of packing or unpacking
String str = "123";
int n = convert.toint32 (str);//Whether the two types have occurred boxing or unpacking, to see if there is an inheritance relationship between the two types of


int n = 10;
Object o = n;//boxed value type = = Reference type N =>o
int nn = (int) o;//unboxing

C # Base value classes and reference types

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.