Chapter II in-depth C # data types

Source: Internet
Author: User

  

Drill down into C # data types: Value (no ref) + value = invariant value (no ref) + citation = variable (with ref) + value/citation = variable

1. Value types and reference types

1. Reference types

Originated from the System.Object family.

(1) class

(2) Interface: interface

(3) array

(4) Strings: string

2. Value types

Originated from the System.ValueType family

The memory area where the value type data resides is the stack.

3. Value type:

(1) Basic data type {int,long,double,byte~~~~}

(2) Enum: enum

(3) Structure: struct

2. Structural body

1. Definition:

Access modifier struct struct name

{

Structural body

}

(1) Structs can have fields, methods, fields cannot be assigned initial values.

(2) can not new, but conditional, the struct has member variables and member methods, member variables are not assigned, call member methods, not new will error, so generally first new.

For example:

public struct student{public int num; public void  Show () {}}

  

static void Main (string[] args) {    Student stu;    stu.num;       stu.show ();  }//Does not assign a value to the member variable, error

  

static void Main (string[] args) {    Student stu;    stu.num=10;       stu.show ();  }//Assign value to member variable without error

  

static void Main (string[] args) {    Student stu=new Student ();    stu.num;        stu.show (); }//new out, no error

3. Crating and Unpacking

Tip: Try to reduce boxing and unpacking as they consume the program's performance.

Chapter II in-depth C # data 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.