NET Basic Course--type foundation (NET Beauty)

Source: Internet
Author: User

1. Type: value type reference type.

Classification by: How the type is allocated in memory. The value type is on the stack, and the reference type is in the managed heap.

noun : Stack-All variables are allocated on the stack, except that the value type directly contains the data, and the reference type contains an address that points to the managed heap object.

A variable that contains the address of an object on a heap is called a variable that refers to this object or variable that references this object .

value type : Simple Type (base Class library type alias) int byte etc.

Declaring an int type is actually a struct-type variable that declares a System.Int32 that contains all the fields in the value type (here, the struct)

Structure Enumeration

Reference type : Class delegate interface, etc.

2. Initialization of variables

 Public struct Point    {        publicint  x;    }     class program    {        staticvoid Main (string[] args)        {point            p;// The struct type variable itself is an instance of            Console.WriteLine (p.x); // compiler hints may refer to Unassigned fields x   should be preceded by p.x=10;             Console.readkey ();        }    }

But there is another situation that passes directly and prints out 0. Note the difference. The reason is that the fields are also initialized when the class is initialized .

 Public class Point    {        publicint  x;    }     class program    {        staticvoid Main (string[] args)        {            new point ();//Note this  must be initialized first, otherwise the compiler prompts for an unassigned local variable            Console.WriteLine (p.x);            Console.readkey ();        }    }

3. Object references are not set to an instance of an object, as shown in the following example. The reason for this is that a is an object reference, and no new has been pointed to any actual object.

Object A = null; Console.WriteLine (A.tostring ());

NET Basic Course--type foundation (NET Beauty)

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.