C #-Data Type

Source: Internet
Author: User

In C #, data types that comply with common language standards (CLS) can be divided into two types: Value Type and reference type. There is a big difference between the two. The value type represents actual data, but the value is stored in the memory. Value types are stored in the stack. Reference data is stored in the heap.

1. Value Type

(1) Integer

(2) balanced

In C #, the character type (char) adopts the Unicode character set. The length of a Unicode standard character is 16 characters (two bytes ).

(3) floating point

C # provides three master types: float, double, and decimal ). <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + ICAgIDxpbWcgc3JjPQ = "http://www.2cto.com/uploadfile/Collfiles/20140317/20140317090722269.jpg" alt = "Z? Http://www.bkjia.com/ OS/"target =" _ blank "class =" keylink "> the default floating point number is double. To declare the float and decimal types, you also need to add the suffix F and M after the decimal, for example, 2 (representing system. double); 2F (representing system. single); 2 M (representing system. decimal ).

(4) Boolean

The bool type in C # Corresponds to the system. Boolean structure. Optional values: True and False. The memory size is 1 byte/8 bits. (* There is no correspondence with other values. 0 cannot be regarded as FALSE, and other values are TRUE)

(5) Enumeration type

Enumeration is a composite value type. It is mainly used to indicate a combination of logically associated items, which is defined by the keyword enmu.

Enmu Fruit {apple, banana, pear, peach };

Fruit f1;

F1 = Fruit. banana

(6) Structure Type

The struct class is a user-defined value type data type. The process of organizing a series of related information into a single entity is the process of creating a structure.

Struct person

{

String m_name; // name

Int m_age; // age

String m_sex; // gender

}


2. Reference Type

The reference types include class, interface, delegate, and array ).

(1) class)

A class is a set of objects with the same data structure and operation. The new keyword must be used to declare the instance for creating a class.

The fundamental difference between a class and a structure is that the structure is a value type, and the class is a reference type. For value types, each variable directly contains all its own data. Each time a variable is created, a zone is opened in the memory. For reference types, each variable only stores references to the data stored in the target. Each time a variable is created, a pointer pointing to the target data is added.
(2) interface)
To call each other between applications, an agreement must be reached in advance. the called party describes the services that it can provide in the agreement. In C #, this protocol is an interface. The method declaration in the interface definition does not include the access restriction modifier or the method Execution Code. (* If a class inherits an interface, it must implement the service defined by this interface. That is, the method in the implementation interface .)
(3) delegate)

Delegate terms encapsulate the call process of a method.
The use process of delegation is divided into three steps:
1. Define delegate void HelloDelegate ();
2. instantiate HelloDelegate hd = new HelloDelegate (p1.Say); // method called by p1.Say
3. Call hd ();

(4) array (array)
Arrays are mainly used for batch processing of data of the same data type. In C #, arrays must be initialized before they can be used.
For example, int [] array1 = new int [3] {2, 3, 5 };

Int [] array1 = {2, 3, 5 };
In an array, the most common attribute is Length, which indicates the Length of the array.

The content and usage of the reference type will be described in a later blog.


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.