C # types and variables

Source: Internet
Author: User

There are two types of 1.c#: value types and reference types. A variable of a value type directly contains data, whereas a variable of a reference type stores a reference to the data (called an "object"). With reference types, two variables can reference the same object, so an operation performed on one variable may affect the object of another variable. With value type , each variable has its own copy of the data, so an operation performed on one variable does not affect the other (except for the ref and out parameter variables);

2.c# value types are subdivided into simple types, enum types, struct types, and nullable value types. C # Reference types are subdivided into class types, interface types, array types, and delegate types.

3. Value types

A. Simple type:

Signed integral type: sbyte (s = signed, 8 b), short (+ b), int (+), long (64).

Unsigned integral type: Byte (8), ushort (U = unsigned), Uint,ulong,

Unicode characters: char utf-16;

IEEE floating point: float,double 32-bit single-precision and 64-bit double-precision IEC-60559 formats represent 7-bit precision and 15-bit precision

High precision floating point: decimal 128-bit data type for financial and currency calculations at least 28-bit precision

Boolean: BOOL

B. Enum type: Format enum E {...} The user-defined type

C. struct type: Form struct S {...} The user-defined type

D. Nullable value type: An extension of all other value types that have a value of NULL.

4. Reference type:

A. Class type:

Final base class for all other types: Object

Unicode string: string utf-16 code unit

Format is class C {...} The user-defined type

B. Interface type: User-defined type with format: interface I {...}

C. Array types: one-dimensional and multidimensional, e.g. int[] and int[,];

D. Delegate type: Delegate int D (...) The user-defined type

5. Type declaration specifies the name and member of the new type

The A.class type defines a data structure that consists of members (fields) and function members (methods, properties, and others). Class types support single inheritance and polymorphism, and derived classes can be extended and specifically targeted at the base class mechanism.

The b.struct type defines the structure that contains the data members and function members, which is known to the class type. However, unlike classes, structs are value types and generally do not require heap allocation. Struct types do not support user-specified inheritance, and all struct types are implicitly inherited type Object

The C.interface type defines a contract as a set of named Public function members. A class or struct that implements interface must provide an implementation code for an interface function member. Interface can inherit multiple base interfaces, class and strut can implement multiple interfaces

The D.delegate type represents a method that references a specific parameter list and return value type. A delegate allows you to treat a method as an entity that can be assigned to a variable and passed as a parameter. The delegate is similar to the function type provided by the functional language. Delegates are also similar to the concept of function pointers in some other languages. But unlike function pointers, delegates are not only object-oriented, but also type-safe.

The E.enum type is a unique type that contains a named solid. Each enum type has an underlying type (must be one of eight integral types). The set of values for the enum type is the same as the value set of the underlying type.

6.c# supports any type of one-dimensional and multidimensional arrays.

Array declaration assignment, non-0 start, copy, unsafe array access: http://www.cnblogs.com/Demon-Su/p/7440672.html

。 More old do not knock, https://docs.microsoft.com/zh-cn/dotnet/csharp/tour-of-csharp/types-and-variables; I didn't see that. The non-nullable value type, Think those 4 lines are illogical. Superficial understanding, and then go deep.

C # types and variables

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.