2nd Chapter Core C #

Source: Internet
Author: User

1. Variables must be initialized before they are used, and VAR declaration variables must be initialized. int A; var a=1;

2. Constant const modifier const double pi=3.14; A constant declaration must be initialized. Constants can no longer be modified with static.

int a=10;

const int B=10/2; correct b=5;

const int b= A/2; Error declaration constants

3. Data type atmosphere value type and reference type.

struct: struct (directly derived from System.ValueType);
   value type:
   Integral type: Short (system.int16), ushort (system.uint16), int (System.Int32), uint (System.UInt32), Long (System.Int64), ULONG (System.UInt64 ),
   sbyte (System.SByte), Byte (System.Byte),    
   Character type: char (System.Char),
   float: float (system.single), double (system.double);
   High precision Decimal Type: decimal (System.Decimal).
   bool Type: bool (alias of System.Boolean);
   enum: enum (derived from System.Enum);       

3.2 Reference type and its base class:
    string: String (System.String).
    Arrays: Elements of arrays (derived from System.Array), whether reference types or value types, are stored on the managed heap;
    Classes: Class (derived from System.Object);
    interfaces: interface;
    Delegate: Delegate (derived from System.Delegate),
    object: (System.Object);
3.3 attribute of value type:
   All value types for   1.c# are implicitly derived from System.ValueType.
    2. Each value type has an implicit default constructor to initialize the default value for that type.
    3. All value types are sealed (seal), so new value types cannot be derived.
    4. Instances of value types are typically allocated on the thread stack (static allocations), but in some cases can be stored in the heap.
3.4 Attributes of reference type reference types:
    All reference types of 1.c# are implicitly derived from System.Object.
    2. A reference type can derive a new type.
    3. Reference types can contain null values.
    4. The assignment of a reference type variable copies only references to the object, not the object itself.
    5. Objects of the reference type are always allocated (dynamically allocated) in the process heap.
3.5 difference between a value type and a reference type

All types that inherit system.value are value types, and other types are reference types.
A reference type can derive a new type, while a value type cannot; the reference type is stored in the heap, and the value type can be stored in the heap or stored in the stack.
Reference types can contain null values, value types cannot (exceptions to nullable types in value types), and assignments of reference type variables copy only references to objects, not the object itself.
When a value type variable is copied, the contained value is copied. When comparing two value types, the value content comparison is made, and the reference address comparison is made when comparing two reference types.
Value types are more efficient in memory management and do not support polymorphism, and are suitable as vectors for storing data; reference types support polymorphism and are suitable for defining the behavior of an application.

Nullable type (derived from system.nullable generic struct, system.nullable<int> ss = new system.nullable<int> (); SS = 1; equal to int? A=1;)
Note: Whether a nullable type belongs to a value type or a reference type

2nd Chapter Core C #

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.