C # Fundamentals-Data types

Source: Internet
Author: User

Pre-defined Types

C # provides 16 predefined types, including 13 simple types and 3 non-simple types.

The predefined simple types include the following 3 types:

    • 11 Types of numeric values
      • Signed and unsigned integer types of different lengths (8 types)
      • Floating-point type float and double (2 kinds)
      • High precision Decimal type decimal (1 kinds) decimal type is commonly used in the calculation of the ratio of goods
    • A Unicode character type char
    • A Boolean type

3 kinds of non-simple types

    • String, which is an array of Unicode characters
    • Object, which is the base class for all other types
    • Dynamic, which is used by assemblies written in Dynamics languages

The basic types of the C # language include 8 types of integers, 2 binary floating-point types, 1 decimal floating-point types, 1 Boolean types, and 1 character types!

Predefined simple types represent a single data item, and the following table lists these types, the range of values, and the corresponding underlying. NET Type

Predefined non-simple types are as follows:

User-defined Type

In addition to the 16 predefined types provided by C #, you can also create your own types. There are 6 types that allow users to create

    • Classes type (Class)
    • struct type (struct)
    • Array type (arrays)
    • Enum type (enum)
    • delegate type (delegate)
    • Interface type (interface)
Stacks and heaps

A running program uses two memory regions to store data: stacks and heaps

Stack

The stack is a memory data, a last-in-first-out data structure. Stacks store several types of data:

    • Values for certain types of variables
    • Current execution Environment of the program
    • Arguments passed to the method
Features of the stack
    • Data can only be inserted or deleted from the top of the stack
    • Putting the data on top of the stack is called stacking.
    • Removing data from the top of the stack is called a stack

Heap

A heap is an area of memory that, unlike a stack, can be inserted or deleted from anywhere in the heap's memory data

Although the program can save data in the heap, it is not possible to delete them by deleting them. Automatically cleans up useless heap objects when the CLR's automatic GC determines that a program's code will no longer access a data item

Value types and reference types

The type of the data item defines the amount of memory required to store the data and the data members that make up the type. The type also determines where the object is stored in memory---stack or heap

Types are divided into two kinds: value types and reference types

    • Value types require only a single piece of memory to store the actual data
    • Reference type requires two segments of memory
      • The first segment stores the actual data, which is always in the heap
      • The second paragraph is a reference that points to where the data is stored in the heap

Categories for C # types

This morning lists all the types that can be used in C # and their categories: value types or reference types

Variable
    • A variable is a noun that represents the data stored in memory when the program executes
    • C # provides 4 types of variables

End

Finally took the first step ...

C # Fundamentals-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.