New knowledge of C #

Source: Internet
Author: User

I am engaged. NET work has been a period of time, before graduation has been thinking of doing C + +, and later for various reasons (related to the school tutor), toward. NET, so you can fill in the basics of. NET from time to time because your own. NET knowledge is not very solid. Every morning before work, read a Anytao teacher's "You must know. NET" series blog (Ps. Very appreciate the Anytao teacher's speaking style, speak very delicate), so warm know new, record the relevant knowledge.

Before learning C + +, the understanding of new is that all use new, is to create an object, for the value type of the variable is not available new, only the type of reference type can be used to create an object with new, because C + + is not a fully object-oriented language. For C + +, new is used to create an object, which means that a memory space is opened on the heap and that it is released manually, otherwise it will cause memory overflow.

For the. NET c#,new is not so, and will evolve more functions-constraints. In C #, new A variable, and that means to open up memory on the managed heap, the value type can also use new, for example: int a = new int (), for such a new variable comes out, just on the stack (stack, actually always want to not understand why call "stack" instead of stack, called "Stack" Wouldn't it be clearer to separate it from the "heap"? The above initializes an int variable and assigns a value of 0 by default.

The following is a verification applet

namespace fornew{    class  program    {        staticvoid Main (string [] args)        {            intnewint();            Console.WriteLine (i);            Console.read ();     }}}

Output is: 0

In addition, new can be used within a generic class to constrain a generic type to explicitly take a constructor without parameters, for example:

  

    class where New ()    {        publicstringgetset;}    }

When the template class is used, the T type must have a constructor with no arguments, or the compilation will fail.

This time write a bit hastily, tomorrow to add the relevant content, there is no place, welcome to point out the discussion. Thanks again for Anytao Teacher's teachings, attached to his "You must know the. NET" series Blog Address: http://www.cnblogs.com/series/2/

New knowledge of 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.