Constructor 1
Class One
{
Private INT32 NMEM; PRIVATE STRING STRMEM; Public One () {nmem = 5; Strmem = "MEMBER";} PUBLIC ONE (INT32 NVALUE, STRING STRME) {NMEM = nvalue; Strmem = Strvalue;
}
Constructor 2
Class TWO
{
Private INT32 NMEM = 5; private strmem = "member"; public two () {nmem = 5; strMem = "member";} public two (int32 nvalue, string string {nmem = nvalue; strmem = strm = s
}
Constructor 3
Class Three
{
Private int32 nmem = 5; private string strmem = "member"; public three () {} public three (int32 nvalue, string string "{}
}
It can see these three classes of these constructors have obvious differences - in terms of code optimization - it is these different, resulting in the code (exe, dll, etc.) generated during the compilation process (Exe, DLL, etc.) The difference, this one, three compiled the result we use Microsoft's ILDASM tool to see is the same, and the class TWO's compile code is indeed different, and there are more IL code.
The reason is that TWO will include the process of initializing two member variables before calling the constructor, and then call the real constructor to initialize the member variables, which is both equivalent to the variable initialized twice, so if we have some needs The initialization strength field or many overload test functions, then we should consider avoiding the initialization of them or no longer in the constructor when defining a member variable.