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. Windows下的PHP 5.3.x安装 Zend Guard Loader

    PHP5.3之后不再使用Zend Optimizer而是由Zend Guard Loader替换,而Zend Guard Loader安装比前者方便了很多,只有一个dll: 址:http://down ...

  2. 使用Loadrunner对IBM MQ进行性能测试

    一.概述         使用Loadrunner对IBM MQ进行性能测试,需要用到java vuser以及java编码知识.此次先介绍什么是IBM MQ,然后java vuser的使用与配置细节, ...

  3. 使用django发送邮件(smtp)

    首先在 seeting 最下面+上 EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'EMAIL_USE_TLS = False ...

  4. @Transactional注解使用心得

    配置基于注解的声明式事务: ...配置tx,aop的命名空间 xmlns:tx="http://www.springframework.org/schema/tx" xmlns:a ...

  5. 【Java】Maven Tomcat插件使用

    本例是用的是tomcat7-maven-plugin 插件 依赖 tomcat7-maven-plugin 插件的pom.xml依赖为 <dependency> <groupId&g ...

  6. mybatis学习 九 代理开发

    1.作用: 实现创建一个接口后把mapper.xml由mybatis生成接口的实现类,通过调用接口对象就可以获取 mapper.xml 中编写的 sql. 2.实现步骤: 2.1 创建一个接口 (1) ...

  7. 46.UISearchBar的placeholder字体颜色和背景颜色

    1.改变searchbar的searchField属性 UITextField *searchField = [searchbar valueForKey:@"searchField&quo ...

  8. Python中subprocess 模块 创建并运行一个进程

     python的subprocess模块,看到官方声明里说要尽力避免使用shell=True这个参数,于是测试了一下: from subprocess import call import shlex ...

  9. 2018.11.08 UVA11021 Tribles(概率dp)

    传送门 概率dpdpdp简单题. 设f[i]f[i]f[i]表示第iii天的答案. 然后枚举ppp数组从fi−1f_{i-1}fi−1​转移过来就行了. 显然有fi=∑j=0npj∗(fi−1)jf_ ...

  10. JAVA折腾微信公众平台(Token验证)[转]

    JAVA折腾微信公众平台(Token验证) BAE的JAVA还在内测的时候,抱着好奇的态度发邮件申请了内测权限,当时折腾了一天,然后就没折腾了.现在BAE的JAVA都已经正式开放使用了,我又蛋疼的想写 ...