There are two types of constructor:Instance Constructor and Type Constructor(or so-called Static Constructor).

Instance Constructor

When use the new key word to create an instance of class, it will do:

  1. Calculate the size of the class, including the sync block and the type object pointer, so that it knows how much memory the instance needs.
  2. Allocate memory.
  3. Call the the constructor,and it will call the constructor of the base class before the current constructor do anything, and so on to the constructor of the Object class.Note that

Constructor is the only way to initialize a instance or a type, We may have seen codes like below:

class SomeClass
{
private int aField = ;
public SomeClass()
{ }
}

you may think aField is initialized outside the constructor, but this is just a syntactic trick of c#。The compiler will gen some IL codes to set aField to 5 inside the constructor, AND, if there are more than one constructors, each one will contain that piece of IL initailling codes.

Constructor in depth的更多相关文章

  1. js in depth: arrow function & prototype & this & constructor

    js in depth: arrow function & prototype & this & constructor https://developer.mozilla.o ...

  2. js in depth: Object & Function & prototype & __proto__ & constructor & classes inherit

    js in depth: Object & Function & prototype & proto & constructor & classes inher ...

  3. Thread in depth 4:Synchronous primitives

    There are some synchronization primitives in .NET used to achieve thread synchronization Monitor c# ...

  4. 【D3D12学习手记】4.3.8 Create the Depth/Stencil Buffer and View

    我们现在需要创建深度/模板缓冲区. 如§4.1.5所述,深度缓冲区只是一个2D纹理,用于存储最近的可见对象的深度信息(如果使用模板(stencil),则也会存储模板信息). 纹理是一种GPU资源,因此 ...

  5. HOC in Depth

    HOC in Depth Higher-Order Components https://reactjs.org/docs/higher-order-components.html 1. wrappe ...

  6. No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.

    Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...

  7. 分析js中的constructor 和prototype

    在javascript的使用过程中,constructor 和prototype这两个概念是相当重要的,深入的理解这两个概念对理解js的一些核心概念非常的重要. 我们在定义函数的时候,函数定义的时候函 ...

  8. js中的constructor

    定义和用法 constructor 属性返回对创建此对象的 Date 函数的引用. 语法 object.constructor constructor属性不影响任何JavaScript的内部属性.in ...

  9. Java程序设计之Constructor

    插入段代码,下次回忆吧. 先新建一个Person类,代码如下: public class Person { private String name ; private int age; public ...

随机推荐

  1. msgs no .h file

    1.单独编译包,catkin_make --pkg 包名,failed,则 2.进入build下对应的msgs包中,使用make,以及make install,failed,则 3.使用catkin_ ...

  2. Oracle安装配置

    很久没有使用Oracle了,一直做产品使用Mysql,前段时间使用Oracle的一些新经验,占位. 需要整理下....

  3. solr之创建core(搜索核心,包括索引和数据)的方法

    我的solrhome为D:\solrHome\solr step1:进入solrHome会看到collection1文件夹,创建该文件夹的副本,重命名为product 进入product文件夹,进入d ...

  4. object SparkStreaming_StateFul {

    窗口查询 ) )).reduceByKeyAndWindow(_+_,_-_,Seconds(10),Seconds(15))     每隔15s进行查询,查询为前10s的结果.这里的值必须为采集时间 ...

  5. CRC标准以及简记式

    一.CRC标准 下表中列出了一些见于标准的CRC资料: 名称 生成多项式 简记式* 应用举例 CRC-4 x4+x+1 3 ITU G.704 CRC-8 x8+x5+x4+1 31 DS18B20 ...

  6. 【Java】生成图形验证码

    本章介绍一个能生成比较好看的图形验证码类 生成验证码工具类 package com.util; import java.awt.Color; import java.awt.Font; import ...

  7. NYOJ 1016 判断两线段是否相交

    #include<cstdio> #include<cmath> #include<iostream> #include<algorithm> #inc ...

  8. Eclipse使用Git管理项目

    参考来源:https://www.cnblogs.com/wdh1995/p/7004384.html 常见问题: 1. 解决方案:http://www.360doc.com/content/18/0 ...

  9. 2018.12.30 洛谷P4238 【模板】多项式求逆

    传送门 多项式求逆模板题. 简单讲讲? 多项式求逆 定义: 对于一个多项式A(x)A(x)A(x),如果存在一个多项式B(x)B(x)B(x),满足B(x)B(x)B(x)的次数小于等于A(x)A(x ...

  10. 2018.06.26 NOIP模拟 纪念碑(线段树+扫描线)

    题解: 题目背景 SOURCE:NOIP2015−GDZSJNZXSOURCE:NOIP2015-GDZSJNZXSOURCE:NOIP2015−GDZSJNZX(难) 题目描述 2034203420 ...