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 #