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:

  1. class SomeClass
  2. {
  3. private int aField = ;
  4. public SomeClass()
  5. {
  6.  
  7. }
  8. }

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. java性能优化之for循环

    完成同样的功能,用不同的代码来实现,性能上可能会有比较大的差别,所以对于一些性能敏感的模块来说,对代码进行一定的优化还是很有必要的.今天就来说一下java代码优化的事情,今天主要聊一下对于for(wh ...

  2. openssl_error_string()

    其实已经成功了,openssl_error_string()一样会输出错误信息,忽略就好

  3. Python之路(第十六篇)xml模块、datetime模块

    一.xml模块 xml是实现不同语言或程序之间进行数据交换的协议,跟json差不多,但json使用起来更简单, xml比较早,早期许多软件都是用xml,至今很多传统公司如金融行业的很多系统的接口还主要 ...

  4. win7 64位远程连接oracle11g64位

    1.首先下载即时客户端 instantclient-basic-windows.x64-11.2.0.4.0,下载地址:http://www.oracle.com/technetwork/topics ...

  5. sql server profiler 工具使用 sql 语句性能分析

    https://www.cnblogs.com/knowledgesea/p/3683505.html

  6. 服务器重复发送SYN ACK 和 TCP_DEFER_ACCEPT设置

    现象: 以下为其他网站提供,和我遇到的情况一样. 就是服务器老是重复发送 SYN, ACK. 4414.229553  client -> server TCP 62464 > http ...

  7. 【转】Linux修改SSH端口和禁止Root远程登陆

    Linux修改ssh端口22 vi /etc/ssh/ssh_config vi /etc/ssh/sshd_config 然后修改为port 8888 以root身份service sshd res ...

  8. crt转cer ,6.0以上的android系统证书请求配置

    1.在服务器人员,给你发送的crt证书后,进到证书路径,执行下面语句  openssl x509 -in 你的证书.crt -out 你的证书.cer -outform der 这样你就可以得到cer ...

  9. 在平台中使用JNDI 数据源

    有些情况下为了系统的安全性考虑,可以将数据源配置成JNDI,在程序中只需要使用 容器的JNDI路径就可以了. 配置方法 1.在容器中配置数据源 <Context path="/&quo ...

  10. 第20章:MongoDB-聚合操作--聚合管道--$unwind

    ①$unwind 在查询数据的时候经常会返回数组信息,但是数组并不方便信息的浏览,所以提供有“$unwind”可以将数组数据变为独立的字符串内容. 将文档中数组类型的字段拆分成多条,每条文档包含数组中 ...